phpMailer - How do you Remove Recipients
You can use clearAllRecipients( )
$mailer->clearAllRecipients( ); // clear all
PHPMailer shows all recipients in the list when sending an email?
You are adding the addresses to the same object, so they are being accumulated. Try deleting each address after sending the message to it:
foreach ($id as $item) {
$mail->addAddress($item);
$mail->Subject = $correo['mailAsunto'];
$mail->Body = $correo['mailMensaje'];
if(!$mail->send()) {
echo 'Error: ' . $mail->ErrorInfo;
} else {
echo 'Mail sent to '.$item.'<br>';
}
$mail->ClearAllRecipients(); ◄■■■■■■■■■■■■■■■■■■■■■■■■■
}
PhpMailer, ClearAddresses() won't work, message get sent to everyone
In your code, change:
$mail->ClearAddresses();
to:
$mail->ClearAllRecipients();
This should fix the problem.
PHPMailer: Send emails to multiple recipients error
@Natrium nearly had it. You're not accessing your array elements correctly. Do it like this:
foreach ($emailto as $contacts) {
$mail->addAddress($contacts['email']);
}
It's also a good idea to check return values, perhaps:
foreach ($emailto as $contacts) {
if (!$mail->addAddress($contacts['email'])) {
echo 'Address rejected: '.$contacts['email'];
}
}
how to send two different messages to two different users phpmailer
You need to clear the recipients list before you add the new address for the second message. If you don't do that, the first recipient will receive the second message as well:
...
$mail->Body =$message1;
$mail->Send();
//message for admin
// Remove previous recipients
$mail->ClearAllRecipients();
// alternative in this case (only addresses, no cc, bcc):
// $mail->ClearAddresses();
$mail->Body =$message2;
//$adminemail = $generalsettings[0]["admin_email"];
// Add the admin address
$mail->AddAddress($adminemail);
$mail->Send();
PHPmailer multiple recipients error
Dig into the source code. Edit PHPMailer.php and find "function MailSend
". (In 5.0.2, it's around line 564.)
In said function, remove the @ error suppressor from each call to mail()
. Make sure error_reporting is set to something reasonable for debugging. When developing, choose something like this:
error_reporting(E_ALL | E_STRICT);
ini_set('log_errors', 'On');
ini_set('display_errors', 'On');
See if PHP shows any errors. PHPMailer only throws the instantiate exception when the last call to mail()
returns something falsey, or if $rt
never gets set, which would mean that if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1)
evaluates to true
.
Are you using safe mode? What do PHP Mailer $mailer->Sender
and ini_get('safe_mode')
say? (My guess: if you are not running in safe mode, but have it set to something like Off
, this code would return true
.)
Related Topics
How Does {} Affect a MySQL Query in PHP
How to Check If a File Exists on a Remote Server Using PHP
PHP Eval and Capturing Errors (As Much as Possible)
How to Use PHP In_Array with Associative Array
How to Embed HTML Files in PHP Code
Add HTML Formatting in PHPmailer
Change Array Key Without Changing Order
iOS Push Notification Does Not Work When Using Crontab Scheduler
Navigate Back with PHP Form Submission
Convert a String to a Double - Is This Possible
How to Move an Array Element with a Known Key to the End of an Array in PHP
How to Get the Value from Object(Stdclass)
Best Way to Determine If a File Is Empty (Php)
Can PHP Asynchronously Use Sockets
Randomly Losing Session Variables Only in Google Chrome & Url Rewriting