使用php邮件程序从localhost发送电子邮件到gmail地址

时间:2015-08-21 03:55:08

标签: email smtp gmail phpmailer

我使用PHP邮件程序通过gmail从localhost发送电子邮件这是我的代码,但主要问题是,当我运行脚本时,不会向我显示任何错误,我没有收到任何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!";
}

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

1 个答案:

答案 0 :(得分:2)

  

服务器:smtp.gmail.com

     

port:587

     

安全tls

尝试改变...... 几年前我听说过这个问题,经过几个小时后,我发现我改变了这个端口