无法让 PHPMailer 在本地工作
Can't get PHPMailer working locally
我正在使用 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 行
我该如何解决这个问题?
来自文档:
The correct fix for this is to replace the invalid, misconfigured or
self-signed certificate with a good one. Failing that, you can allow
insecure connections via the SMTPOptions property introduced in
PHPMailer 5.2.10 (it's possible to do this by subclassing the SMTP
class in earlier versions), though this is not recommended:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
这有效。
我正在使用 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 行
我该如何解决这个问题?
来自文档:
The correct fix for this is to replace the invalid, misconfigured or self-signed certificate with a good one. Failing that, you can allow insecure connections via the SMTPOptions property introduced in PHPMailer 5.2.10 (it's possible to do this by subclassing the SMTP class in earlier versions), though this is not recommended:
$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) );
这有效。