Send mail
How to Send email in PHP.

PHP email() function is use to send emails. look email function carefully.

Syntax:-

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

Required Parameter:-
to :- Receiver, or receivers of the mail like info@gmail.com

subject :- Subject of the email linke This is test mail

message :- Message to be sent. if your message is long(means more than 70 characters). Then divide your message in line and each Line should not more than 70 characters. and Each line should be spearated with (\n) ;
$body ="Client Details As follows"."\n"."Tom"."\n"."Message"."This is my test message."\n"."Room Type".$room;

Optional Parameter:-

headers :- header is use to add extra parameter like From,Cc and Bcc. and Multiple extra headers should be seperated with \r\n.

parameters:- specify add parameters. This parameter is rare in use.

Example 1: Simple Email.

<?php
$to = "shishir06_2007@yahoo.com";
$subject = "Testing mail";
$message = "Hello! This is a simple email message.";
$from = "shishir012010@gmail.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

How to Send Html Mail

Use header to send HTML mail. Declare Content-type:text/html

Code
$headers = "From: $from"."\r\n";
$headers .= 'Content-type: text/html;';

Example 2:- In this example we use html tag and ...

<?php
$to = 'shishir012010@gmail.com';

$subject = 'This is HTML Test Mail';

$message = '
<html>
<head>
<title>This is my test message</title>
</head>
<body>
<b>Contact Person</b>Mr Tom<br>
<img src="http://interiorandfurnitures.com/images/furniture.jpg"/>
</body>
</html>
';

$from='shishir06_2007@yahoo.com';

$headers = "From: $from"."\r\n";
$headers .= 'Content-type: text/html;';

mail($to, $subject, $message, $headers);
?>

Example 3:- Sending mail by HTML form.

<?php
if(isset($_POST['btnsubmit']))
{
$to=$_POST['to'];
$subject=$_POST['subject'];
$message=$_POST['body'];
$from='shishir06_2007@yahoo.com';
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent successfully.";
}
?>
<html>
<body>
<form name="frm" action="" method="post">
<table width="41%" height="206" border="1" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center">Mail Form </td>
</tr>
<tr>
<td width="33%" height="32">To</td>
<td width="52%"><input type="text" name="to"></td>
</tr>
<tr>
<td height="28">Subject</td>
<td><input type="text" name="subject"></td>
</tr>
<tr>
<td>Body</td>
<td>
<textarea name="body" rows="5"></textarea>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input name="btnsubmit" type="submit" id="btnsubmit" value="Send">
</td>
</tr>
</table>
</form>
</body>
</html>


Previous
Next