【问题标题】:Sending an email using PHPMailer and GMAIL SMTP使用 PHPMailer 和 GMAIL SMTP 发送电子邮件
【发布时间】:2012-07-03 20:20:36
【问题描述】:

我已经阅读了网络上的每个示例,但我似乎仍然无法连接到 GMAIL SMTP。这是我正在运行的代码:

include("phpMailer/class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer(); 
$mail->IsSMTP(); // send via SMTP

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myUsername"; // SMTP username
$mail->Password = "myPassword"; // SMTP password
$mail->SMTPDebug = 1;
$webmaster_email = "webMasterEmail@gmail.com"; //Reply to this email ID
$email="someone@gmail.com"; // Recipients email ID
$name="SomeonesName"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Me";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
    echo "Message has been sent";
}

我尝试在此处设置端口,并且我还在 class.smtp.php 文件中使用以下内容进行了当前设置:

$host = "ssl://smtp.gmail.com";
$port = 465;

我不断收到同样的错误,我已确保启用了 ssl。我得到的错误是:

SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it.(10061)

【问题讨论】:

标签: php phpmailer


【解决方案1】:

正如我上面提到的,我已经通过去掉 ; 来启用 ssl与 php_openssl.dll 并重新启动 Apache 就行了。我做了更多阅读,发现有些人在启用命令之前也有“[PHP_OPENSSL]”。我添加了它并重新启动了 Apache,一切正常!感谢所有的cmets

在 php.ini 中:

[PHP_OPENSSL]
extension=php_openssl.dll

【讨论】:

    猜你喜欢
    • 2014-10-19
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 2015-07-08
    • 2011-04-06
    • 2017-10-05
    相关资源
    最近更新 更多