When I include test.com in the subject of an email the email fails to send. I am using phpmailer and office365
This fails:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../../src/Exception.php';
require '../../src/PHPMailer.php';
require '../../src/SMTP.php';
//production Email
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->Host = "smtp.office365.com";
$mail->Port = 587; // TLS only
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;
$mail->Username = "email@domain.com";
$mail->Password = "*********";
$mail->setFrom('email@domain.com', 'reports');
$mail->addAddress('email@domain.com', 'Name');
$mail->Subject = "TEST.com";
$mail->IsHTML(true);
$body = "This is the body.";
$mail->Body="$body"; //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
//$mail->AltBody = 'HTML messaging not supported';
// $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file
if(!$mail->send()){
$display = "Mailer Error: " . $mail->ErrorInfo;
}else{
$display = "Thank you for your submission! ";
}
?>
This works: (the only difference is the a space between Test and .com)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../../src/Exception.php';
require '../../src/PHPMailer.php';
require '../../src/SMTP.php';
//production Email
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->Host = "smtp.office365.com";
$mail->Port = 587; // TLS only
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;
$mail->Username = "email@domain.com";
$mail->Password = "*********";
$mail->setFrom('email@domain.com', 'reports');
$mail->addAddress('email@domain.com', 'Name');
$mail->Subject = "TEST .com";
$mail->IsHTML(true);
$body = "This is the body.";
$mail->Body="$body"; //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
//$mail->AltBody = 'HTML messaging not supported';
// $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file
if(!$mail->send()){
$display = "Mailer Error: " . $mail->ErrorInfo;
}else{
$display = "Thank you for your submission! ";
}
?>
I have no idea after 8 hours of trying and retrying. I looked at Mail flow on EAC and there was nothing about the emails.
I tried everything from Phpmailer error "Could not instantiate mail function" but it gets me this error (this includes adding $mail->isSMTP()):
2023-07-18 15:51:50 Connection: opening to smtp.office365.com:587, timeout=300, options=array()
2023-07-18 15:51:58 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.office365.com:587 (Connection refused) [/home/hmktgroup/public_html/src/SMTP.php line 388]
2023-07-18 15:51:58 SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting