E-mail in PHP

E-mail in PHP

Posted in : PHP Posted on : January 10, 2011 at 5:40 PM Comments : [ 0 ]

This section contains the detail about E-mail in PHP.

E-mail in PHP

For sending e-mail to any person, PHP provide a function known as mail().

The syntax of the mail() function is given below :

mail(to, subject, message, headers, parameters)


 to - Compulsory field, It should contain email of the receiver / receivers.

subject -  Compulsory Field, This field should contain the subject of the email. This parameter cannot contain any newline characters

message -  Compulsory Field, This field contain message body. Each line should be separated with a LF (\n). Lines should not exceed 70 characters.

headers -   Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n).

parameters - Optional. Specifies an additional parameter to the sendmail program.

Example :

This example contains a html contact form and a PHP script to send mail. This will give you a clear idea how to use it.

Html form

<TITLE>Send Email</TITLE>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<td><strong>Send Email</strong></td>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<td><form name="form1" method="post" action="send_mail.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
<td>Message Body</td>
<td><textarea name="message" cols="50" rows="4" id="message"></textarea></td>
<td><input name="e_mail" type="text" id="e_mail" size="50"></td>
<td><input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Reset"></td>


$from ="admin@devmanuals.com";
$to = $_POST['e_mail'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$header="from: Admin <$from>";

//sending email

// display message if message sent to your email
echo "Message successfully sent!";
else {
echo "Message delivery failed...";

Output :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics