【问题标题】:Send Email from localhost to gmail address using php mailer使用 php mailer 从本地主机发送电子邮件到 gmail 地址
【发布时间】:2015-08-21 03:55:07
【问题描述】:

我正在使用 PHP 邮件程序通过 gmail 从本地主机发送电子邮件,这是我的代码,但主要问题是,当我运行脚本时,没有显示任何错误,并且我没有收到任何 gmail id 的电子邮件

include("email/class.phpmailer.php");
$mail = new PHPMailer();
$body = "This is just a Test Email";

$mail->IsSMTP();

// enable SMTP authentication
$mail->SMTPAuth = true;                  

// sets GMAIL as the SMTP server
$mail->Host = "smtp.gmail.com";

// set the SMTP port for the GMAIL server
$mail->Port = 465;                   

// GMAIL username
$mail->Username = "Mygmail id";

// GMAIL password
$mail->Password   = "password";        
$mail->From       = "Mygmail id";
$mail->FromName   = "My Name";

$mail->Subject    = "Testing Message";

$mail->AltBody    = "To view the message, please use an HTML compatible    
email viewer!"; // optional, comment out and test
$mail->WordWrap   = 50; // set word wrap

$mail->MsgHTML($body);

$mail->AddAddress("Receiver Gmail Id");

$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

请不要重复我的问题,因为我尝试了所有其他答案,但没有找到任何解决方案

【问题讨论】:

  • 它是重复的,这被广泛覆盖in the docs,您使用的是旧版本的 PHPMailer,并且未能使用the gmail example provided。一般来说,看起来你并没有很努力。

标签: email smtp gmail phpmailer


【解决方案1】:

服务器:smtp.gmail.com

端口:587

安全 tls

尝试改变它.... 几年前我就听说过这个问题,花了几个小时后,我发现我必须更改端口

【讨论】:

  • 意味着我必须在我的文件中包含该代码 $mail->SMTPSecure = 'tls';并将端口更改为 587 和 $mail->Server = 'smtp.gmail.com';
  • 这是正确的,但它也只说明了 PHPMailer 文档所说的内容,所以这不是新闻!
  • 据我所知,是的,您应该添加/更改它
猜你喜欢
  • 1970-01-01
  • 2015-05-29
  • 1970-01-01
  • 2017-06-30
  • 2012-05-25
  • 1970-01-01
  • 2021-02-12
  • 2018-05-20
  • 1970-01-01
相关资源
最近更新 更多