SMTP connect()失败。突然

时间:2017-11-29 07:06:11

标签: php email smtp phpmailer

你能帮助我吗? 这段代码有什么问题。已经尝试了各种方式,但仍然是SMTP connect()失败。最初电子邮件发送成功,但我尝试在第二天返回SMTP connect()失败,这会出现在我的网站上。

require 'php-mailer/class.phpmailer.php';
require 'php-mailer/class.smtp.php';
require 'php-mailer/PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->SMTPDebug = 0;

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'name@gmail.com';
$mail->Password = '********';
$mail->SMTPSecure = 'tsl';
$mail->Port = 587;

$mail->From = 'example@gmail.com';
$mail->FromName = 'example';

$mail->isHTML(true);
$mail->SetFrom('example@gmail.com', 'example');
$mail->AddReplyTo('example@gmail.com','example');

$mail->Subject = 'My Subject';
$mail->Body = 'Content Mail';
$mail->AltBody = '';

$mail->AddAddress('me@gmail.com', 'My Name');
//$mail->AddAttachment('images/phpmailer.gif');
//$mail->AddAttachment('images/phpmailer_mini.gif');
if(!$mail->send()){
    echo "<h2 style='color:#df0000'>Email not sent!.</h2>";
    echo $mail->ErrorInfo;
}
else{
    echo "<h1>Success !!!</h1>";
}

提前谢谢

0 个答案:

没有答案