PHP邮件程序不起作用

时间:2018-09-22 14:48:29

标签: php smtp


我想用php制作邮件系统。
此代码在本地服务器上有效。
但是,它不能在Live服务器中工作!

那是错误:

2018-09-22 14:29:49 SMTP错误:无法连接到服务器:连接被拒绝(111) SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 邮件错误:SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

那是我的代码:

require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;


$mail->SMTPDebug = 1;                               

$mail->isSMTP();            

$mail->Host = "smtp.gmail.com";

$mail->SMTPAuth = true;                          

$mail->Username = "mygmail@gmail.com";                 
$mail->Password = "mypassword";                           

$mail->SMTPSecure = "tls";                           

$mail->Port = 587;                                   

$mail->From = "mygmail@gmail.com";
$mail->FromName = "Full Name";

$mail->addAddress("mygmail@gmail.com", "Recepient Name");

$mail->isHTML(true);

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";

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


谢谢

0 个答案:

没有答案