a simple way of sending mail with php
January 26, 2007
You can use the mail() function in php to gather and send information from a form to an email address.
To use mail(), pass it a destination email address, a message subject, and a message body.
<?php
mail(’example@example.com’,'My Message Subject’,'My Message Body’);
?>
You can also assign variables in the mail() function.
<?php
$emailaddress = ‘example@example.com’;
$messagesubject = ‘This is my subject’;
$messagebody = ‘This is my message body’;
mail($emailaddress,$messagesubject,$messagebody);
?>
If you wanted send information from a form try this.
Your form should look something like this:
<form method=”post” name=”formname” action=”sendform.php”>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”3″>
<tr>
<td>Name:</td>
<td><input name=”name” type=”text” id=”name”></td>
</tr>
<tr>
<td>Street Address: </td>
<td><input name=”address” type=”text” id=”address”></td>
</tr>
<tr>
<td>City:</td>
<td><input name=”city” type=”text” id=”city”></td>
</tr>
<tr>
<td>Province/State:</td>
<td><input name=”province” type=”text” id=”province”></td>
</tr>
<tr>
<td>Postal Code/ZIP: </td>
<td><input name=”postal” type=”text” id=”postal”></td>
</tr>
<tr>
<td>Phone:</td>
<td><input name=”phone” type=”text” id=”phone”></td>
</tr>
<tr>
<td>Fax:</td>
<td><input name=”fax” type=”text” id=”fax”></td>
</tr>
<tr>
<td>E-mail: </td>
<td><input name=”email” type=”text” id=”email”></td>
</tr>
<tr>
<td> </td>
<td><input type=”submit” name=”Submit” value=”Submit”></td>
</tr>
</table>
</form>
The script on sendform.php to process the form should look like this:
<?php
$emailaddress = ‘example@example.com’;
$messagesubject = ‘This is my subject’;
$messagebody .= “Name: ” . $_POST['name'] . “\n”;
$messagebody .= “Street Address: ” . $_POST['address'] . “\n”;
$messagebody .= “City: ” . $_POST['city'] . “\n”;
$messagebody .= “Province/State: ” . $_POST['province'] . “\n”;
$messagebody .= “Postal Code/ZIP: ” . $_POST['postal'] . “\n”;
$messagebody.= “Phone: ” . $_POST['phone'] . “\n”;
$messagebody .= “Fax: ” . $_POST['fax'] . “\n”;
$messagebody .= “Email: ” . $_POST['email'] . “\n”;
mail($emailaddress,$messagesubject,$messagebody);
$URL=”http://www.example.com”;
header (”Location: $URL”);
?>
Note that when you want to combine variables use the .= operator.
Also note that if you want to redirect the page after running the script use:
$URL=”http://www.example.com”;
header (”Location: $URL”);
Creating PHP Breadcrumbs
February 27, 2006
Good resources to help create PHP Breadcrumps.
The above samples show how to make simple breadcrumbs from directory names, but sometimes that can get a little messy. Here’s a great link showing how to assign “pretty” labels to directory names.
