问题在本地主机中发送电子邮件,但不在liveserver中发送电子邮件

时间:2018-12-09 09:52:52

标签: php phpmailer

我对PHPMailer有问题。 首先,我已经集成了phpmailer,并且在localhost和live server中都没有任何问题地发送了电子邮件。从昨天开始,我遇到了一个问题,无法在本地主机中发送电子邮件,而不能在实时服务器中发送电子邮件。我在localhost发送电子邮件时遇到的错误是

  

电子邮件无法发送给最近批准的成员。 ErrorSMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

这是在实时服务器和本地主机中发送电子邮件的相同代码。

$mail = new PHPMailer;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'someone@gmail.com';                 // SMTP username
$mail->Password = $pw;                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25;                                    // TCP port to connect to
$mail->setFrom('someone@gmail.com', 'Reboot E-Magazine');
$mail->addAddress($email);     // Add a recipient
$mail->Subject = 'Article Confirmation';
$mail->Body =
'Reboot Magazine
--------------------------------------------------------------------
Your article was not been approved due to certain reasons.
Please ensure the article are well-written and relevant to the topic.
--------------------------------------------------------------------

Sincerely,
Riyaz Ahmad
Admin of Reboot E-magazine';

if(!$mail->send())
{
    $error = "Email could not be sent. Error". $mail->ErrorInfo;
}
else
{
    $msg = "Email has been sent to notify the member";
}

1 个答案:

答案 0 :(得分:1)

我相信这里已经回答了

SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed

评论

  

$ mail-> isSMTP();

通常可以解决此问题。