Home | Php | JavaScript | SQL | HTML | Server Admin | Tools
Php
Welcome

Gzip Compression
Date and Time
Sending Mail
Header Last Modified
Other sites
Image Editor
Top 10 web hosting reviews

The Php mail() function

People often get all worked up about getting the Php mail function to work. There are lots of complicated scripts out there to send mail but it really is not that hard. Here is the simplest way to do it.

The Easiest Way to Send Mail with Php

Example Code
<?php
    mail
'you@yoursite.com''Subject Line''Text of the Message.' );
?>

This is probably the quickest, easiest way of sending mail with Php. However, you might want something more sophisticated. For example, maybe you want to set the "from" address or the likes. Well here you go.

How to Send Extra Headers

Example Code
<?php
     
// Put the info into some variables
     
$to_address 'you@yourdomain.com';
     
$subject 'Subject - Enquiry';
     
$extra_headers "From: $NAME_OF_SENDER <$EMAIL_OF_SENDER>\r\n";
     
$extra_headers .= "Reply-To: $EMAIL_OF_SENDER\r\n";
     
$extra_headers .= "Return-Path: $EMAIL_OF_SENDER\r\n";
     
$message 'Blah Blah Blah';
     
// Call the mail function with the variables.
     
mail$to_address$subject$message$extra_headers );
?>

In this example the variables $NAME_OF_SENDER and $EMAIL_OF_SENDER would need to be set before mailing. Normally you could use and HTML form element to pass the data to the script and then send the email based on that.



Link back to this page

Copy and paste this HTML code into your page to link back to this very page:
     

Or just link to the WebCodingTech site:
     

And your link will look like this:
      Inspired by stuff found at www.webcodingtech.com.

Thanks!





Copyright © 2005 WebCodingTech.com Our URL is: http://www.webcodingtech.com