Stream_socket_enable_crypto():对等证书CN =`* .webhostbox.net'与使用PHPMailer的预期CN =`mail.maydomain.com'不匹配

问题描述:

我正在使用PHPMailer发送电子邮件,但出现错误。我的域名不是SSL。如果我使用smtp.gmail.com与我的Gmail ID,然后在电子邮件要收件箱中,但是当我使用我的主机信息,然后我得到一个错误Stream_socket_enable_crypto():对等证书CN =`* .webhostbox.net'与使用PHPMailer的预期CN =`mail.maydomain.com'不匹配

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 ='假';然后没有得到一个错误,但电子邮件将发送垃圾邮件。 即使我尝试下面的代码。

$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 = "[email protected]"; 
$mail->Password = "Pass#@123"; 
$mail->setFrom('[email protected]', 'naren'); 
$mail->addReplyTo('[email protected]', '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"; 
} 
+0

任何人都可以帮助我吗? –

Read the PHPMailer docs的错误点,你的;它解释了如何诊断这个问题。

您要求连接到smtp.gmail.com,但实际上您正在连接到mail.webhostbox.net(我从您发布的内容中收集)。毫不奇怪,该TLS证书与gmail的域名不匹配,因此失败。您试图通过禁用验证来强制它正常工作,这不会像您现在伪造发件人地址一样工作,从而导致SPF失败,并因此最终会被拒绝或发送垃圾邮件,正如您所看到的。

您需要更改您的发件人地址以匹配ISP提供的SPF,让他们让您正确使用SMTP,或切换到更开明的ISP。

+0

我的ISP提供商存在问题。我 –

+0

如果我使用smtp.gmail.com,那么电子邮件将收件箱。我在我自己的服务器上遇到了这个问题。现在我的问题得到解决。 –