首页 > 解决方案 > PHPMailer 6.2 stream_socket_client

问题描述

我改用 PHPMailer 6.2(这是主版本,也是最新版本)。

我在 Windows Server 2019 上使用 Apache 2.4。我使用的 PHP 版本是 7.4.12。

按照本教程:https ://www.youtube.com/watch?v=t0zwgJrSHd4

使用以下代码我运气不佳:

<?php
use PHPMailer\PHPMailer\PHPMailer;

require 'PHPMailerAutoload.php';
require 'phpmailer/class.phpmailer.php';
require 'phpmailer/class.smtp.php';

$mail = new PHPMailer();

$mail->SMTPDebug = 4;  

$mail->isSMTP(); 
$mail->Host = 'xx.x.x.xxx'; 
$mail->SMTPAuth = false; // <- just changed to false
$mail->Username = 'mycompany@email.com'; 
$mail->Password = 'mypassword';  
$mail->Port = 25;  
$mail->SMTPSecure = 'tls';
// update
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);   
// end update

$mail->setFrom('mycompany@email.com', 'Mailer');
$mail->addAddress('myoutsidefacingemail@gmail.com', 'TEST'); 
$mail->addReplyTo('mycompany@email.com', 'Information');
$mail->addCC('mycoworker@email.com');

$mail->isHTML(true);  

$mail->Subject = 'This is a test subject';
$mail->Body    = '<h1>This is the HTML message body <b>in bold!</b></h1>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
  echo 'Message could not be sent.';
  echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent';
}
?>

我已经编辑了这个问题,因为我做了一些更新(见上面的代码)。

使用上述内容,我可以在我们的网络上内部发送电子邮件。

问题是发送外部电子邮件。

这是我在尝试发送到我的 gmail 时收到的错误消息(我没有粘贴完整的错误消息,只是最后几行):

2021-01-21 21:02:26 CLIENT -> SERVER: QUIT
2021-01-21 21:02:26 SMTP INBOUND: "221 2.0.0 Service closing transmission channel"
2021-01-21 21:02:26 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2021-01-21 21:02:26 Connection: closed
SMTP Error: The following recipients failed: myoutsidefacingemail@gmail.com: 
SMTP; Unable to relay recipient in non-accepted domain
Message could not be sent.Mailer Error: SMTP Error: The following recipients failed: myoutsidefacingemail@gmail.com: SMTP; Unable to relay recipient in non-accepted domain

标签: phpsmtpphpmailerapache2.4stream-socket-client

解决方案


推荐阅读