Send Mail Using mail() Function in PHP

The mail() function allows you to send emails directly from a script. Remember, that most of shared hosting providers require (for security reasons) to use the domain name of your hosting in "FROM" email, e.g. from@yourdomain.com for http://yourdomain.com site.

[View All Snippets]
Show Plain Text »
  1. <?php
  2. $to = 'myfriend@gmail.com';
  3. $subject = 'Test Email';
  4. $body = 'Body of your message here. You can use HTML tags also, e.g. <br><b>Bold</b>';
  5. $headers = 'From: John Smith'."\r\n";
  6. $headers .= 'Reply-To: from@email.me'."\r\n";
  7. $headers .= 'Return-Path: from@email.me'."\r\n";
  8. $headers .= 'X-Mailer: PHP5'."\n";
  9. $headers .= 'MIME-Version: 1.0'."\n";
  10. $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
  11. mail($to, $subject, $body, $headers);
  12. ?>
Create Your Free Account
Please remember that this information is essential to use our services correctly.
After creating the account you will be able to download all of our FREE products.
Fields marked with * are mandatory






Please send me information about updates, new products, specials and discounts from ApPHP!
We recommend that your password should be at least 6 characters long and should be different from your username/email. Please use only letters of the English alphabet to enter your name.

Your e-mail address must be valid. We use e-mail for communication purposes (order notifications, etc). Therefore, it is essential to provide a valid e-mail address to be able to use our services correctly.

All your private data is confidential. We will never sell, exchange or market it in any way. Please refer to Privacy Policy.

By clicking "Create Account", you are indicating that you have read and agree to the ApPHP Terms & Conditions.