【发布时间】:2018-01-05 04:19:40
【问题描述】:
我正在使用 PHPMailer 发送电子邮件,但收到错误消息。我的域不是 SSL。如果我将 smtp.gmail.com 与我的 Gmail id 一起使用,那么电子邮件将发送到收件箱,但是当我使用我的托管详细信息时,我会收到一个错误
Warning: stream_socket_enable_crypto(): Peer certificate CN=`*.webhostbox.net' did not match expected CN=`mail.mydomain.com' in C:\xampp\htdocs\sendmail\mail\class.smtp.php on line 337
Mailer Error: SMTP connect() failed.
如果我将$mail->SMTPSecure = 'tls'; 设置为 $mail->SMTPSecure = 'false';然后没有收到错误,但电子邮件会变成垃圾邮件。
即使我尝试了下面的代码。
$mail->SMTPOptions = array (
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true));
你能帮我解决这个问题吗?
谢谢
require 'mail/PHPMailerAutoload.php';
function sendMail($subject, $content, $email){
$phpMailerSubject = $subject;
$phpMailerText = $content;
$phpMailerTo = $email;
include 'mail/PHPMailerConfig.php';
}
PHPMailerConfig.php
<?php
//Create a new PHPMailer instance
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = 'mail.mydomain.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "abc@mydomain.com";
$mail->Password = "Pass#@123";
$mail->setFrom('abc@mydomain.com', 'naren');
$mail->addReplyTo('abc@mydomain.com', 'naren');
$mail->addAddress($phpMailerTo, 'Customer');
$mail->Subject = $phpMailerSubject;
$mail->msgHTML($phpMailerText);
$mail->AltBody = ' ';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "sucessfully";
}
【问题讨论】:
-
有人可以帮我吗?