Send Mail using mail function in PHP


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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'."
  6. ";
  7. $headers .= 'Reply-To: from@email.me'."
  8. ";
  9. $headers .= 'Return-Path: from@email.me'."
  10. ";
  11. $headers .= 'X-Mailer: PHP5'."\n";
  12. $headers .= 'MIME-Version: 1.0'."\n";
  13. $headers .= 'Content-type: text/html; charset=iso-8859-1'."
  14. ";
  15. mail($to, $subject, $body, $headers);
  16. ?>

URL: http://www.apphp.com/index.php?snippet=php-send-mail-using-mail-function

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.