Sending eMail Using PHP

by Hiroshi on June 13, 2008

in Mail

Simply we are using a form in HTML file which posts information to the next PHP file which sends email then. Create a web page for form, PHP script file, put these scripts in these and try the following method to send email using PHP.

Form Code

<form name="mailform" method="POST" action="mail_submit.php">
<td align="center" valign="middle"><table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150">Name *</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td width="150">Company *</td>
<td><input name="company" type="text" id="company"></td>
</tr>
<tr>
<td width="150">Address *</td>
<td><input name="address" type="text" id="address"></td>
</tr>
<tr>
<td width="150">Phone *</td>
<td><input name="phone" type="text" id="phone"></td>
</tr>
<tr>
<td width="150">Cell *</td>
<td><input name="cell" type="text" id="cell"></td>
</tr>
<tr>
<td width="150">Email *</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td width="150">How did you find me *</td>
<td><select name="find" size="1">
<option>Select</option>
<option value="google">Google</option>
<option value="yahoo">Yahoo</option>
<option value="spider">Spider</option>
<option value="brochure">Brousher</option>
<option value="friend">Friend</option>
<option value="other">Other</option>
</select></td>
</tr>
<tr>
<td width="150">Comments *</td>
<td><textarea name="comments" rows="10" id="comments"></textarea></td>
</tr>
<tr>
<td width="150">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="150" height="25">Catagories</td>
<td height="25">One
<input name="cb1" type="checkbox" id="cb1" value="yes" checked>
Two <input name="cb2" type="checkbox" id="cb2" value="yes">
Three <input name="cb3" type="checkbox" id="cb3" value="yes">
Four <input name="cb4" type="checkbox" id="cb4" value="yes"></td>
</tr>
<tr>
<td width="150">Script is </td>
<td>
<p>
<label>
<input name="r1" type="radio" value="good" checked>
Good</label>
<br />
<label>
<input type="radio" name="r1" value="nice">
Nice</label>
<br />
</p></td>
</tr>
<tr>
<td width="150">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="150">&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table></td>
</form>

PHP File Code

<?php
// request variables // make sure you request all variables correctly //
$email=$_REQUEST["email"];
$name=$_REQUEST["name"];
$subject=$_REQUEST["subject"];
$message=$_REQUEST["message"];
$from=$_REQUEST["from"];
$company=$_REQUEST["company"];
$cb1=$_REQUEST["cb1"];
$cb2=$_REQUEST["cb2"];
$cb3=$_REQUEST["cb3"];
$cb4=$_REQUEST["cb4"];
$cb1=$_REQUEST["cb1"];
$address=$_REQUEST["address"];
$cell=$_REQUEST["cell"];
$find=$_REQUEST["find"];
$r1=$_REQUEST["r1"];
$phone=$_REQUEST["phone"];
$comments=$_REQUEST["comments"];
 
if ($name)
{
$myfrom = $email;
$myemail = "youremailaddress@hotmail.com";
$todayis = date("l, F j, Y, g:i a") ;
if ($cb1!="yes")
$cb1="No";
if ($cb2!="yes")
$cb2="No";
if ($cb3!="yes")
$cb3="No";
if ($cb4!="yes")
$cb4="No";
$subject= "Message From Website";
$message = "
Date : $todayis
Name: : $name
company: : $company
address: : $address
phone: : $phone
cell: : $cell
email: : $email
I found u by: : $find
One: : $cb1
Two: : $cb2
three: : $cb3
Four: : $cb4
comments : $comments
Good or nice : $r1
";
$from = "From: $myfrom\r\n";
mail($myemail, $subject, $message, $from);
$subject2="Thanks for contacting me.";
$message2="Dear $name,
Thanks for contacting me, I will respond you shortly.";
$from2 = "From: $myemail\r\n";
mail($email, $subject2, $message2, $from2);
$sent = "your message has been recieved, Thanks for feedback";
echo "$sent";
}
?>

Related Posts

Previous post:

Next post: