How To Send Email Using PHP Mail Function

Photo of Mike Dalisay
Modified Monday, January 24, 2011
by - @ninjazhai
Hi guys! Today we'll be sending email using the PHPMail Function. I think this is much easier than using a PHP library like PHPMailer. You don't have to specify your email address and password to sent email, just specify the "from" email address you want. But you must have a live mail server. By the way I had a previous post "How To Send Email Using PHPMailer and GMail"

How To Send Email Using PHP Mail Function
Much easier.

 $name = "Your Name";
 $email = ""
 $subject = "Some subject here.";
 $message = "Your message here.";
 $recipient_email = "";

 $headers  = "MIME-Version: 1.0\r\n";
 $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
 $headers .= "From: $name <$email> \n";

 $body = '<b>Name: </b> ' . $name . '<br />';
 $body .= '<b>Email: </b>' . $email . '<br />';
 $body .= '<b>Message: </b>' . $message . '<br /><br />';
 $body .= 'You can add something here like signature.';

 if( mail($recipient_email, $subject, $body, $headers) ){
   echo "Message has been successfully sent.";
  echo "Sending failed.";
In case you want to test this code, you may download it and change the variables to your settings:

That's it, hope it helps. :)
For FREE programming tutorials, click the red button below and subscribe! :)
Thanks for the comments!
"First do it, then do it right, then do it better."
~ Addy Osmani
"Talk is cheap. Show me the code."
~ Linus Torvalds
Let's Stay Connected!
g+ r
Android app on Google Play
© 2011-2014 The Code Of A Ninja. All rights reserved. Proudly Powered by Google Blogger. Images, logos, marks or names mentioned herein are the property of their respective owners.