I switched over to using PHPMailer 6.2 (which is the master version, and most recent version).
I am using Apache 2.4 on a Windows Server 2019. The version of PHP I am using is 7.4.12.
Following this tutorial: https://www.youtube.com/watch?v=t0zwgJrSHd4
I am not having much luck using the below code:
<?php
use PHPMailerPHPMailerPHPMailer;
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 = '[email protected]';
$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('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'TEST');
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$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';
}
?>
I have edited this question as I have made some updates (see above code).
Using the above, I can send email internally, on our network.
The problem is sending external email.
Here is the error message I am receiving when trying to send to my gmail (I did not paste the full error message, just the last few lines):
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: [email protected]:
SMTP; Unable to relay recipient in non-accepted domain
Message could not be sent.Mailer Error: SMTP Error: The following recipients failed: [email protected]: SMTP; Unable to relay recipient in non-accepted domain
question from:
https://stackoverflow.com/questions/65831206/phpmailer-6-2-stream-socket-client 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…