|
PHP Tutorial Home
Basic PHPPHP IntroductionPHP Installation PHP Syntax PHP Variables PHP Form Variables PHP If Statements PHP Switch Statements PHP Arrays PHP While Loops PHP For Loops PHP Operators PHP Functions Advanced PHPPHP IncludePHP Upload File PHP File PHP Mail PHP Database Driven Website PHP Summary Got a MySpace Page?Get "www.yourname.com" for your MySpace page. Learn how >>. |
PHP MailYou can use PHP to dynamically send emails to one or more recipients. This can be handy for a lot of reasons, for example:
The PHP mail() FunctionTo send email using PHP, you use the mail() function. This accepts 5 parameters as follows (the last 2 are optional)
Below is an explanation of the parameters.
Sending an EmailYou could send email by simply doing this:
Although, in reality, you would probably set your parameters up as variables. Also, if the email was triggered by a user, you would probably provide them with feedback to say that the email had been sent.
HTML EmailsTo send an HTML email, the process is the same, however, you need to provide additional headers (as well as an HTML formatted message). Note that you need to separate each header with a carriage return. For Windows systems, use this code:
For UNIX systems, use this code:
Difference Between UNIX and Windows Code?You probably noticed in the above example that there's a Windows version and a UNIX version. The only difference is in the way the carriage returns are specified. On Windows it's "\r\n", on UNIX it's "\n". The PHP specification stipulates that you should use "\r\n" for creating the carriage returns. This should work fine on Windows systems. UNIX systems however, have a tendency to add "\r" to the "\n", therefore resulting in "r\r\n", which of course, wouldn't work. Therefore, we simply leave out the "\r" on the UNIX version. Enjoy this website?
Oh, and thank you for supporting Quackit! |
Featured Template:
(Build your websites in minutes!) |