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 address开发者_StackOverflow中文版es. Any ideas why this is happening? Is there a different way to add multiple e-mail addresses?
Cheers, Gazler.
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
.)
did you try just $mail->AddAddress($value);
?
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 thephp.ini
settings); - the openssl module is enabled (execute a
phpinfo()
and search for OpenSSL)
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?
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.
'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
精彩评论