无法让PHPMailer在本地工作

时间:2016-01-10 03:23:18

标签: php email smtp localhost phpmailer

我正在使用PHPMailer,它在我的服务器上工作正常,但在我的localhost上没有。我用来发送的功能是:

function sendEmail($mail, $toEmail, $toName, $subject, $message, $noHtmlMessage) {
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'christopherpickardco.netfirms.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'webmaster@christopherpickard.com';                 // SMTP username
    $mail->Password = 'myPassword';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('webmaster@christopherpickard.com', 'ChrisComposes.com'); //
$mail->addAddress($toEmail, $toName);     // Add a recipient. Right now this goes to me, in the end it will go to Chris
$mail->addReplyTo('webmaster@christopherpickard.com', 'ChrisComposes.com');

$mail->Subject = "ChrisComposes.com: " . $subject;
$mail->Body    = $message;
$mail->AltBody = $noHtmlMessage;

$mail->send(); 
} 

这在我的服务器上运行正常但在我的localhost上我收到一个错误:警告:stream_socket_enable_crypto():对等证书CN = smtp.eigbox.net' did not match expected CN= christopherpickardco.netfirms.com'在/ Users / ChristopherPickard / Web_Development / chriscomposes / includes第344行的/phpmailer/class.smtp.php

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:-1)

来自docs:

  

正确的解决方法是更换无效,配置错误或   带有好签名的自签名证书。如果做不到这一点,你可以允许   不安全的连接通过引入的SMTPOptions属性   PHPMailer 5.2.10(通过子类化SMTP可以做到这一点   早期版本中的类),但不建议这样做:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

这很有效。