PHPmailer multiple recipients error

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 12:23:04

问题


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 am getting the error 'Could not instantiate mail function'.

If I remove an item from the array it works fine, but gives an error on when trying to add 2 or more addresses. Any ideas why this is happening? Is there a different way to add multiple e-mail addresses?

Cheers, Gazler.


回答1:


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.)




回答2:


did you try just $mail->AddAddress($value); ?




回答3:


Most of the times this error is caused when from header is 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 the mail is enabled in the server (and the php.ini settings);
  • the openssl module is enabled (execute a phpinfo() and search for OpenSSL)



回答4:


I just looked through the source code of PHPMailer, the message "Could not instantiate mail function" indicates that mail() returns false.

Can you try the same function, but with two different email-addresses that you know usually accepts emails?




回答5:


Try downloading latest version of PHPMailer if you are not using one, it has bug fixes. Chances are that your mailer class has been messed with.




回答6:


'Could not instantiate mail function'. Just check your mailer function working or not. many time this error cause due to limitation from hosting provider .many time Hosting provider block your mailing feature then usually you get this error



来源:https://stackoverflow.com/questions/2277466/phpmailer-multiple-recipients-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!