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.

0


a source to share


6 answers


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

.)

+4


a source


Have you tried simple $mail->AddAddress($value);

?



0


a source


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 settings php.ini

    );
  • openssl module enabled (execute phpinfo()

    and search for OpenSSL)
0


a source


I just looked at the PHPMailer source code, the message "Failed to create mail function" means it mail()

returns false.

Can you try the same feature but with two different email addresses that you know usually accept emails?

0


a source


Try downloading the latest PHPMailer if you are not using it, it has bug fixes. Chances are your mail class is confusing.

0


a source


'Failed to create mail function. Just check if the mail program is working or not. many times this error occurs due to restrictions on the part of the hosting provider. A lot of the time the hosting provider blocks your mail function, then usually you get this error.

0


a source







All Articles