PHPmailer multiple recipients error
I have the following code with PHPmailer:
$tomailn[0] = 'imap2@gazler.com';
$tomailn[1] = 'imap@gazler.com';
foreach($tomailn as $value)
{
$mail->AddAddress($value, '');
}
But I get the error "Failed to create mail function".
If I remove an item from the array, it works fine, but gives an error when I try to add 2 or more addresses. Any idea why this is happening? Is there a way to add multiple email addresses?
Cheers, Gazler.
a source to share
Go to source code. Modify PHPMailer.php and search for " function MailSend
". (In 5.0.2 it is around line 564.)
In the above function, remove the @error suppressor from every call before mail()
. Make sure error_reporting is set to something sane 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 there are any bugs in PHP. PHPMailer only throws an instance exception when the last call mail()
returns something false, or if $rt
never set, which means it 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')
? (My guess: if you are not running in safe mode, but install it something like Off
this, this code will return true
.)
a source to share
In most cases, this error occurs when the header is from
not set or is invalid. Try setting this variable:
$mail->From = 'valid@mailaddress.com';
If it still doesn't work, try one of the following:
- check if
mail
the server is enabled (and settingsphp.ini
); - openssl module enabled (execute
phpinfo()
and search for OpenSSL)
a source to share