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">
<td width="150">Name *</td>
<td><input name="name" type="text" id="name"></td>
<td width="150">Company *</td>
<td><input name="company" type="text" id="company"></td>
<td width="150">Address *</td>
<td><input name="address" type="text" id="address"></td>
<td width="150">Phone *</td>
<td><input name="phone" type="text" id="phone"></td>
<td width="150">Cell *</td>
<td><input name="cell" type="text" id="cell"></td>
<td width="150">Email *</td>
<td><input name="email" type="text" id="email"></td>
<td width="150">How did you find me *</td>
<td><select name="find" size="1">
<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>
<td width="150">Comments *</td>
<td><textarea name="comments" rows="10" id="comments"></textarea></td>
<td width="150">&nbsp;</td>
<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>
<td width="150">Script is </td>
<input name="r1" type="radio" value="good" checked>
<br />
<input type="radio" name="r1" value="nice">
<br />
<td width="150">&nbsp;</td>
<td width="150">&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>

PHP File Code

// request variables // make sure you request all variables correctly //
if ($name)
$myfrom = $email;
$myemail = "";
$todayis = date("l, F j, Y, g:i a") ;
if ($cb1!="yes")
if ($cb2!="yes")
if ($cb3!="yes")
if ($cb4!="yes")
$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: