【问题标题】:Can't get PHPMailer working locally无法让 PHPMailer 在本地工作
【发布时间】:2016-04-14 14:12:14
【问题描述】:

我正在使用 PHPMailer,它在我的服务器上运行良好,但在我的本地主机上却不行。我用来发送的函数是:

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(); 
} 

这在我的服务器上运行良好,但在我的本地主机上出现错误:警告:stream_socket_enable_crypto(): Peer certificate CN=smtp.eigbox.net' did not match expected CN=christopherpickardco.netfirms.com' in /Users/ChristopherPickard/Web_Development/chriscomposes/includes/phpmailer /class.smtp.php 第 344 行

我该如何解决这个问题?

【问题讨论】:

  • 它只能在指定的站点上工作不是很明显吗?因此,当您在 localhost 上运行它时,八盒.net 将主机名接收为 localhost 而不是 christopherpicardco.netfirms.com。所以由于安全问题,它不起作用。
  • 如果这对我来说很明显,我就不会问了,但是谢谢。很多人似乎都在本地主机上工作,所以一定有办法
  • 您使用哪个服务器软件作为 localhost?
  • 很明显,因为这个确切的错误已经包含在文档中,所以去阅读它们。

标签: php email smtp localhost phpmailer


【解决方案1】:

来自文档:

解决此问题的正确方法是替换无效、配置错误或 一个好的自签名证书。否则,您可以允许 通过 SMTPOptions 属性引入的不安全连接 PHPMailer 5.2.10(可以通过子类化 SMTP 来做到这一点 早期版本中的类),但不建议这样做:

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

这行得通。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    • 2012-12-29
    相关资源
    最近更新 更多