I'm using the latest version of PHPMailer to send an email to 3 emails on the same domain.
All the emails, The one I send emails from and the 3 other emails I send messages to are on the same domain, It's a business Gmail account.
Here is the code:
//Including PHPMailer files
require_once('phpmailer/src/phpmailer.php');
require_once('phpmailer/src/SMTP.php');
require_once('phpmailer/src/Exception.php');
$msg = '';
//List of emails
$recipients = array('info@mydomain.com', 'help@mydomain.com', 'schedule@mydomain.com');
//Initializing PHPMailer
$mail = new PHPMailer\PHPMailer\PHPMailer(); // Passing `true` enables exceptions
try {
//Sender data
$mail->setFrom('admin@mydomain.com', 'Admin');
$mail->addReplyTo('info@mydomain.com', 'Admin');
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Hello World!';
$mail->Body = 'Hello World!';
$mail->AltBody = 'Hello World!';
//Loop through the emails list
foreach ($recipients as $recipient) {
$mail->addAddress($recipient);
if (!$mail->send()) {
echo "Mailer Error (" . str_replace("@", "@", $recipient) . ') ' . $mail->ErrorInfo . '<br />';
break; //Abandon sending
} else {
echo "Message sent to :" . ' (' . str_replace("@", "@", $recipient) . ')<br />';
}
// Clear all addresses and attachments for next loop
$mail->clearAddresses();
$mail->clearAttachments();
}
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
When I run the script on the same domain I get the following output:
Message sent to : (info@mydomain.com)
Message sent to : (help@mydomain.com)
Message sent to : (schedule@mydomain.com)
But when I check the inbox of these emails, I don't find the email.
I tried to get the mail.log
file by:
ini_set('mail.log', __DIR__ . 'mail.log');
But it didn't work and I can't use $mail->SMTPDebug = 2;
, As I'm not using SMTP
.