Bohack

Check In and Tune Out!
 
 
« Dell OpenManage Problem – Hangs at Precopy Preparation
Renaming VMWare Files In Virtual Center »

A Simple PHP mail() Function For Testing SMTP Delivery



Making sure mail is sent properly from a PHP website is a bit difficult when it’s not your server, like shared hosting. You never have access to the mail logs, so you can’t see mail moving. I host several websites on shared hosting and recently found my CMS was not sending emails to me. So I opened a ticket and I concluded it to be a SNAFU.

I’m never satisfied when I conclude something doesn’t work because it’s complex. The best thing to do is to snap into diagnostic mode. The first rule of diagnosis of the problem is start simple and work from there. The saying of getting to the root of the problem is accurate.

I looked at the CMS code and concluded that the function being called to send mail is the PHP function of mail(). So I needed to check the PHP mail function by itself, without the complexity of the CMS. If the mail() function sends mail, then the problem is the CMS or my email. If the mail() function does not send mail, then my provider has something that they can work with and I can present the problem to them. Simple I created a simple PHP script called testmail.php with this short little string of code:

<?php
$to = 'youraccount@youremail.com';
$subject = 'Sent on '.date("F j, Y, g:i a");
$message = 'Test message';

mail($to, $subject, $message);
?>

This routine will send mail to the $to variable and also tag the date in the subject. This is all done via the sendmail variable in php, you can do a phpinfo() to find which program sends mail. This can be handy if you need to see when it left the other system and came into yours. Just look the original header and you will be able to see all details.

In the end my problem resulted in my SPAM filter catching the email thus never showing up in the Inbox. Stupid problem, but until you verify the flow of mail with your hosting provider and scale your complexity back… You won’t solve the problem.

Tags: php, Web

This entry was posted on Saturday, January 9th, 2010 at 1:05 pm and is filed under Programming, Scripts.
You can follow any responses to this entry through the RSS 2.0 feed.
Both comments and pings are currently closed.

One Response to “A Simple PHP mail() Function For Testing SMTP Delivery”

  1. websites Says:
    May 3rd, 2010 at 2:33 am

    This is certainly a real perfect resource that you’re providing and you also give it away for nothing. I enjoy seeing websites that realize the value of offering a excellent resource for free. I really loved reading your article. Thank you!

  • Channels

    • Beer (2)
    • Blog (1)
    • Exchange (2)
    • Ham Radio (1)
    • Homebrew (3)
    • Linux / Unix (4)
    • Misc (1)
    • Mods (4)
    • Networking (1)
    • Programming (4)
    • Recipes (2)
    • Scripts (7)
    • Security (1)
    • Software (2)
    • Spam (1)
    • Telco (7)
    • Virtual PC (1)
    • VMware (3)
    • VOIP (3)
    • Windows (16)
    • Windows 2008 (4)
    • Windows 7 (5)
  • Archives

    • September 2012
    • April 2012
    • March 2012
    • February 2012
    • January 2012
    • November 2011
    • September 2011
    • July 2011
    • April 2011
    • February 2011
    • January 2011
    • October 2010
    • August 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • June 2009
    • May 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
  • Links

    • Blogarama Blogarama – The Blog Directory
    • BlogHub Blog Directory
    • Blogrankings Technology Blogs – Blog Rankings
    • Blogville.us blogville.us
    • Buzzerhut free directory | buzzerhut.com
    • Ontoplist Online Marketing
    • Primechoiceautoparts Discount Auto Parts
    • PTC My Employer
 

  Copyright - Bohack 2025 ©