Search code examples
phpphpmailer

PHPMailer Not sending Mails To Some Gmail Accounts


I'm using PHPMailer (Version 5) for user registration. (When user registers to my site the Profile activation code is sent to user to activate it). PHPMailer works, I tested it many times (I registered Myself with other mails and with gmail too for testing purposes, I always got the activation code), but many users complain that they not getting the activation codes and then I have to send them manually... I can't understand what is the problem (When I checked my users database there are many users that got activation codes, but also that couldn't received).. I debug PHPMailer, but there is not any error or problem...

I'm Using PHPMailer With Gmail SMTP:

$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';              
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 587; 
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "MyPassword";
$mail->From = "[email protected]";
$mail->FromName = 'www.mysite.com';

$mail->AddAddress($email);
$mail->WordWrap = 80;
$mail->IsHTML(true);
$mail->Subject = 'Registration';
$mail->Body    = $message;
$mail->AltBody = $message;
$mail->Send();

I also tried to use SSL-465, but the result is the same..

Please Help!

Thank you very much in advanced...


Solution

  • I Solved this problem from server (host). I checked mail functions / configs and found "MAX_EMAIL_PER_HOUR" was set to 30 (Really strange, by default It is 100) So I changed it to 500 and It fixed all PHPMailer Issues...

    In addition:

    Enabling "Allow less secure apps" will usually solve many problem for PHPMailer, and it does not really make your app significantly less secure. (When enabling Google warns you that the App is insecure).

    If you Need More security, PHPMailer added support for XOAUTH2 for google, you can use it...

    I haven't used this technology before, but I'll play with it as soon as possible ;)

    With Best Wishes!