Reputation: 3141
So I'm working on a Wordpress installation for a buddy, making a form send to his email address. I've been testing out the mail function and.. Well, it seems like after a certain number of times I test it, it just stops working...
I've got an
if( mail( ... ) )
echo " =) things are workin out all right...";
else
echo "fuk...";
statement checking to see whether mail is sending.. and after a while it just stops working.
Is there a setting that limits the number of mails that can be set or something? Am I just sending too much mail?!
Now.. After I wait a while (say a day), mail is suddenly working again.. hm...
Upvotes: 2
Views: 2018
Reputation: 157
Some hosts limit how many messages can be sent per minute/hour/day.
To work around this, I set up a second Gmail account to send messages from a script using PHPMailer, then made this script (called mail.php
):
<?php
include_once 'phpmailer/class.phpmailer.php';
function do_mail($from, $name, $to, $subject, $message, $debug = false) {
$blah = base64_decode('base64-encoded password here');
$mail = new PHPMailer();
$mail->IsSMTP();
if($debug) $mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = '[email protected]';
$mail->Password = $blah;
$mail->SetFrom($from, $name);
$mail->AddAddress($to, $to);
$mail->Subject = $subject;
$body = $message;
$mail->MsgHTML($body);
$mail->AltBody = $message;
if($mail->Send()) {
return true;
} else {
return $mail->ErrorInfo;
}
}
?>
Then, to send a message:
<?php
include_once 'mail.php';
$result = do_mail('[email protected]', 'First Last', '[email protected]', 'Subject here', 'message here');
// Or, with debugging:
$result = do_mail('[email protected]', 'First Last', '[email protected]', 'Subject here', 'message here', true);
// Print the result
var_dump($result);
?>
Upvotes: 2