使用PHPMailer和GMAIL SMTP发送电子邮件 [英] Sending an email using PHPMailer and GMAIL SMTP

查看:655
本文介绍了使用PHPMailer和GMAIL SMTP发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have read every example out in the web and I still cant seem to connect to the GMAIL SMTP. Here is the code that I am running:

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文件中也进行了以下设置:

I tried setting the port in here and I also have the current set up with the following in the class.smtp.php file:

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

我一直收到相同的错误,并且确保已启用ssl.我得到的错误是:

I keep getting the same error and I have made sure that ssl is enabled. The error I get is:

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

推荐答案

如上所述,我已经通过摆脱;来启用了ssl;与php_openssl.dll并重新启动Apache.我做了一些进一步的阅读,发现在启用命令之前,有些人也有"[PHP_OPENSSL]".我添加了它并重新启动了Apache,一切正常!感谢您的所有评论

As I mentioned above I had already enabled ssl by getting rid of the ; on the line with php_openssl.dll and restarting Apache. I did some more reading and I found out that some people also had "[PHP_OPENSSL]" before the enabling command. I added it and restarted Apache and everything is working! Thanks for all the comments

在php.ini中:

[PHP_OPENSSL]
extension=php_openssl.dll

这篇关于使用PHPMailer和GMAIL SMTP发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆