我知道这个问题已经被问了很多,我已经阅读了大部分内容。
尝试使用我的Gmail帐户使用PHP Mailer和WAMP Server从PHP发送电子邮件时出现此错误。
这是我的phpmailer功能代码。正在从数据库中检索所有设置。因为它是一个多用户应用程序。
// Email Settings
$from=$details->from;
$mailer=$details->mailer;
$subject=$details->subject;
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = $settings->debug; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $settings->host; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $settings->login; // SMTP username
$mail->Password = $pass; // SMTP password
$mail->SMTPSecure = $settings->security; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $settings->port; // TCP port to connect to
//From
$mail->setFrom($from, $mailer);
//Recipients
$mail->addAddress($details->to,$details->recipientName); // Add a recipient // Name is optional
$mail->addReplyTo($from, $mailer);
foreach($quote->cc as $cc)
{
$mail->addCC($cc);
}
//Attachments
foreach($quote->attachments as $file)
{
$mail->addAttachment($file); // Add attachments // Optional name
}
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = 'Non-HTML Mail Clients Not Supported, Please View This email in a browser or get a HTML friendly Email Client.';
$mail->send();
}
catch (Exception $e)
{
$return=array(1,'Error: '.$mail->ErrorInfo);
}
return $return;
}
我得到的错误是
2017-12-04 07:15:26 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP w9sm23070345pfk.16 - gsmtp<br>
2017-12-04 07:15:26 CLIENT -> SERVER: EHLO projects<br>
2017-12-04 07:15:26 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [49.213.37.11]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>
2017-12-04 07:15:26 CLIENT -> SERVER: STARTTLS<br>
2017-12-04 07:15:27 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS<br>
SMTP Error: Could not connect to SMTP host.<br>
2017-12-04 07:15:27 CLIENT -> SERVER: QUIT<br>
2017-12-04 07:15:27 <br>
2017-12-04 07:15:27 <br>
SMTP Error: Could not connect to SMTP host.<br>
[1,"Error: SMTP Error: Could not connect to SMTP host."]
感谢任何帮助。
PS:我正在使用的设置是
我怀疑它是否是我的代码。因为如果它是我的代码,那么它不会与我的组织的电子邮件服务器一起使用,它不像gmail那样复杂。
答案 0 :(得分:1)
我看到一个像你的问题一样的错误,我通过以下方式解决了我的问题:
添加一些代码:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
这是有效的!