0

I'm trying to excute php mail() function from my script, but I'm recieve the mail to late (after 2 hours!!!) this is mail sipmle script:

<?php 
   // print phpinfo(); 
error_reporting(-1);
ini_set('display_errors',1);
set_error_handler("var_dump");
if(mail('abdelkhalek.oumaya@gmail.com', 'test 05082016', 'test')){
    echo 'done';
}
?>
  • Likely nothing to do with PHP. Check your MTA logs, your SMTP server logs (if you're using one), could be getting help up by content filters. Too many possible reasons. – Jonnix Sep 05 '16 at 13:58
  • Delivery is not controlled by PHP. There are 2 mail servers between you PHP and your Receiving the mail. They can take as long as they like to virus check etc etc etc an email – RiggsFolly Sep 05 '16 at 14:01

2 Answers2

2

This is most likely not an issue in PHP but rather an issue with your hosting provider. Some shared hosting provider queued emails before sending them. So if that happens to be your webhost, then that is the issue. I have seen their email take 1,2 hours sometimes on shared hosting server.

Try using PHPMailer may be you found some improvement in your time. https://github.com/PHPMailer/PHPMailer

Bhavin
  • 2,070
  • 6
  • 35
  • 54
1

I recommend you to use a mail library like PHP_MAILER to take car of mail. For the delay normaly its instantly but without log we can find an answedr.

Try using php mailer and maybe it will work instantly.

https://github.com/PHPMailer/PHPMailer

MaximeK
  • 2,039
  • 1
  • 10
  • 16
  • thank you very much for your answer , can you help me to find how to use or add phpmailer without composer !!!! :( – Oumaya Abdelkhalek Sep 05 '16 at 14:24
  • 1
    Just download the zip. And copy `PHPMailerAutoload.php` and every file starting with `class.XXXX.php`. in your script just type `require 'PHPMailerAutoload.php';` like in the basic exemple :) – MaximeK Sep 05 '16 at 14:56
  • thank youuuu ^_^ actualy i trying with phpmailer and i have this response : SMTP -> FROM SERVER:220 orevon.eu ESMTP Postfix (Debian/GNU) SMTP -> FROM SERVER: 250-orevon.eu 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN SMTP -> FROM SERVER:250 2.1.0 Ok SMTP -> FROM SERVER:250 2.1.5 Ok SMTP -> FROM SERVER:354 End data with . SMTP -> FROM SERVER:250 2.0.0 Ok: queued as 174BD4484A1 SMTP -> FROM SERVER:221 2.0.0 Bye Message Sent OK it look like my server make the send email in queued :(( – Oumaya Abdelkhalek Sep 05 '16 at 15:35
  • there is any function to make the mail first in queu ????? – Oumaya Abdelkhalek Sep 05 '16 at 15:39
  • 1
    i advice you tu use a gmail or other free email service to take car of the sending. http://tutorialspots.com/php-sending-e-mail-with-gmail-smtp-and-phpmailer-update-2015-1788.html – MaximeK Sep 05 '16 at 15:46
  • @MaximeK Gmail rate limits and will disable your account if you [send to too many people](https://support.google.com/a/answer/2956491#sendinglimitsforrelay) – Machavity Sep 05 '16 at 16:00
  • 2K email is a lot, and can be split over more than 1 account. For starting its better without debian and smtp knowledge – MaximeK Sep 05 '16 at 16:05