6 replies
How to check whether the mail has been successfully send using mail function in php?

Please any one tell me ......... thanks
#php
  • Profile picture of the author Pointer
    I always test using my own email as the recipient address. That way when you get the emails from the form, you know it's working. Then just change the email in the PHP from your's to the email that it should be sending to.
    {{ DiscussionBoard.errors[2165882].message }}
  • Profile picture of the author Manfred Ekblad
    You can also test it by sending a copy (bcc) of every email to your own email address during testing. It would be clever to create a new gmail account for that purpose

    $headers = "From: me@mydomain.com"; //sender
    $headers .= "\r\nCc: copy@$adomain.com"; //copy to
    $headers .= "\r\nBcc: bcc@$adomain\r\n\r\n"; //bcc to <---this it the important one for testing your mail function
    $headers .= "\r\nX-Mailer: PHP/" . phpversion(); //sending mail client

    mail($to,$subject,$message,$headers);

    Hope that helps
    {{ DiscussionBoard.errors[2166073].message }}
  • Profile picture of the author newmoon
    Is there two topics for same issue? I guess I already answered.

    PHP Code:
    if(mail(TO,SUBJECT,BODY,HEADERS)){
    //show success messages
    } else {
    //show failure messages

    That means the function returns Boolean (True/False) after sending mail. If it succeeds, it returns TRUE otherwise FALSE.

    Hope that helps!
    {{ DiscussionBoard.errors[2167299].message }}
  • Profile picture of the author jwiggs
    Originally Posted by astle000 View Post

    How to check whether the mail has been successfully send using mail function in php?

    Please any one tell me ......... thanks
    The mail() function returns false if there was an error, so you can capture the return value in a variable and then branch based on its true/false value to add in error handling/logging.

    WARNING! be aware that this only tells you that mail was successfully accepted for delivery by whatever server is configured as the SMTP server for your mail setup. If the email has to go through multiple hops to reach the destination, there could be errors along the way that you won't catch. It's always a good idea to send a few test emails, preferably to multiple host destinations, before saying you're good.
    {{ DiscussionBoard.errors[2168732].message }}
  • Profile picture of the author weaveronline
    yes...this can be checked using an if - else condtion
    Signature

    Thanks & Regards,
    Reach us at dukeduke600@gmail.com.
    Web Design| Logo Design | Banner Design | Web Development | Mobile Applications [iPhone/iPad/Android/Windows Phone]

    {{ DiscussionBoard.errors[2170158].message }}
  • Profile picture of the author sunnygal
    I like to create a log file that can be turned on and off.

    I use it during development and then turn it off once the code moves to production, but I can always turn it back on quickly if I need to do some debugging.
    {{ DiscussionBoard.errors[2175633].message }}

Trending Topics