...

View Full Version : PHP mail scripting--- need a little help



06f150
12-05-2010, 04:49 AM
So I am almost done with a website for my business....last part is to finish up the PHP mail script for my submit box.

For the life of me I can't get this thing to work....I am getting it down with pretty good now with general coding but I can not figure this PHP scripting out for the life of me.


Can anybody help me out?

it would be awesome!!!

Thanks guys!

Lamped
12-05-2010, 04:53 AM
Some code would be really helpful... Show us what you've got so far.

06f150
12-05-2010, 05:04 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> <script type="text/javascript" src="js/lightbox.js"></script> <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationCheckbox.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script> <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> <link rel="icon" href="favicon.png" type="image/png"> <title>Northern Property Services, LLC</title> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <link href="SpryAssets/SpryValidationCheckbox.css" rel="stylesheet" type="text/css" /> <link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <div id="logo"><a href="http://www.northernproservices.com"><img src="images/npslogo.png" alt="bog 1" border="0"/></a></div> <div id="header"> <ul> <li><a href="index.html">Home</a></li>
<li><a href="lawn.html">Lawn Services</a></li> <li><a href="irrigation.html">Irrigation Services</a></li> <li><a href="work.html">Our Work</a></li> <li><a href="quotes.html">Request A Quote</a></li> <li><a href="contact.html" class="lastchild">Contact Us</a></li> </ul> </div> <div id="content"> <h1>Request A Quote</h1> <div id="left"> <div class="text">

<h2>Fill in all available fields</h2>

<form name="contactform" method="post" action="send_form_email.php">




<table width="500px" cellpadding="0" cellspacing="24" border="0">
<tr>
<td width="50%" valign="top">






<table width="450px" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="40%" valign="top">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>

<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>

<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>



<tr>
<td valign="top"">
<label for="address">Address *</label>
</td>
<td valign="top">
<input type="text" name="address" maxlength="50" size="30">
</td>
</tr>



<tr>
<td valign="top"">
<label for="city">City *</label>
</td>
<td valign="top">
<input type="text" name="city" maxlength="50" size="30">
</td>
</tr>


<tr>
<td valign="top"">
<label for="zip_code">Zip Code *</label>
</td>
<td valign="top">
<input type="text" name="zip_code " maxlength="50" size="30">
</td>
</tr>






<tr>
<td valign="top">
<label for="home_phone">Home Phone *</label>
</td>
<td valign="top">
<input type="text" name="home_phone" maxlength="30" size="30">
</td>
</tr>



<tr>
<td valign="top">
<label for="alternate_phone">Alternate Phone </label>
</td>
<td valign="top">
<input type="text" name="alternate_phone" maxlength="30" size="30">
</td>
</tr>

<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>

<tr>
<td valign="top">
<label for="company_name">Company Name </label>
</td>
<td valign="top">
<input type="text" name="company_name" maxlength="80" size="30">
</td>
</tr>




</td>
</tr>
</table>
</table>


<table width="500px" cellpadding="0" cellspacing="24" border="0">
<tr>
<td width="50%" valign="top">
<b>LAWN CARE REQUESTS</b>
<br/><br/>






<input type="checkbox" name="Lawn" value="weekly_lawn_care" /> Weekly Lawn Care
<br>

<input type="checkbox" name="Lawn" value="storm_clean_up" /> Storm Clean-up
<br>

<input type="checkbox" name="Lawn" value="hedge_&_shrub_trimming" /> Hedge & Shrub Trimming
<br>

<input type="checkbox" name="Lawn" value="landscaping" /> Landscaping
<br>

<input type="checkbox" name="Lawn" value="fertilization" /> Fertilizing
<br>

<input type="checkbox" name="Lawn" value="aeration" /> Aeration
<br>

<input type="checkbox" name="Lawn" value="dethatching" /> Dethatching
<br>
<input type="checkbox" name="Lawn" value="snow_removal" /> Snow Removal
<br>





</td>
<td width="50%" valign="top">

<br>
<br>
<input type="checkbox" name="Lawn" value="fall_or_spring_clean_up" /> Fall or Spring Clean-up
<br>

<input type="checkbox" name="Lawn" value="storm_clean_up" /> Storm Clean-up
<br>

<input type="checkbox" name="Lawn" value="gutter_cleaning" /> Gutter Cleaning
<br>

<input type="checkbox" name="Lawn" value="gutter_screen_installation" /> Gutter Screen Installation<br>


<input type="checkbox" name="Lawn" value="mulching" /> Mulching
<br>

<input type="checkbox" name="Lawn" value="flower_bed_maintenance" /> Flower Bed Maintenance
<br>

<input type="checkbox" name="Lawn" value="overseeding" /> Overseeding
<br>

<input type="checkbox" name="Lawn" value="other" /> Other
<br>


</td>
</tr>
</table>


<table width="500px" cellpadding="0" cellspacing="24" border="0">
<tr>
<td width="50%" valign="top">
<b>IRRIGATION REQUESTS</b>
<br>
<br>
<input type="checkbox" name="Irrigation" value="winterization" /> Fall Winterzation (blowout)
<br>
<input type="checkbox" name="Irrigation" value="spring_start_up" /> Spring Start-up
<br>
<input type="checkbox" name="Irrigation" value="Add_on" /> Relocating of Zones/ Heads
<br>

<br>


Number of Zones <select name="Number of Estimated Zones">
<option value="0" selected="selected">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20+">20+</option> </select>



</td>
<td width="50%" valign="top">
<br>
<br>
<input type="checkbox" name="Irrigation" value="Check-up Visit" /> Check-up Visit
<br>
<input type="checkbox" name="Irrigation" value="repair" /> Repair
<br>

<input type="checkbox" name="Irrigation" value="other" /> Other





</td>
</tr>
</table>









<table width="500px" cellpadding="0" cellspacing="24" border="0">
<tr>
<td width="50%" valign="top">
<br />
<label for="comments">Additional Requests/ Comments</label>
</td>
<td valign="top">
<br />
<textarea name="comments" maxlength="1000" cols="23" rows="4"></textarea>
</td>
</tr>


<tr>
<td colspan="2" style="text-align:center">

<input type="submit" value="Submit">

<input name="Clear" type="reset" value="Reset" />
</td>
</tr>
</table>
</form>


&nbsp;




</div> <div class="photos"> <a href="images/edging1.jpg" rel="lightbox" title="Edging"> <img src="images/edging1.jpg" alt="bog 1" width="96" height="76" border="0" /> </a> <a href="images/firepit1.jpg" rel="lightbox" title="Mulching"> <img src="images/firepit1.jpg" alt="bog 2" width="96" height="76" border="0" /> </a> <a href="images/mulching1.jpg" rel="lightbox" title="Mowing"> <img src="images/mulching1.jpg" alt="bog 3" width="97" height="76" border="0" /> </a> </div> <div class="clear"></div> </div> <div id="right"> <h2>Specials</h2> <a href="specials.html">Northern 5-Star lawn Care package</a> <p>Weekly cut, trim, along with a fall and spring clean-up.<br /><br /> Save 10% on this package.</p> <span><a href="specials.html">More</a></span> </div> <div class="clear"></div> </div> <div id="footer"> Northern Property Services, LLC copyright all rights reserve. </div> </div> <script type="text/javascript"> <!-- var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2"); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3"); var sprycheckbox1 = new Spry.Widget.ValidationCheckbox("sprycheckbox1"); var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4"); var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5"); var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6"); var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7"); var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1"); var sprytextfield8 = new Spry.Widget.ValidationTextField("sprytextfield8"); var sprytextfield9 = new Spry.Widget.ValidationTextField("sprytextfield9"); //--> </script> </body> </html>

Lamped
12-05-2010, 05:26 AM
First of all, you want to change the checkbox names of Lawn to Lawn[] and Irrigation to Irrigation[] - that way PHP will know it's an array and let us read it.

Next:



// This be send_form_email.php

if (!$_POST['email']) {
echo('Oh no! There\'s no email address!');
}

if (@mail(
$_POST['email'],
'Web form submit',
"
Web Form Email\n
From: {$_POST['first_name']} {$_POST['last_name']}\n
Address: (I'm sure you get the point here and can copy the line above...)

Lawn: ".implode(', ', $_POST['Lawn'])."\n
Irrigation: ".implode(', ', $_POST['Irrigation'])."\n
",
'From: server@'.$_SERVER['HTTP_HOST']
)) {
echo('Sent');
} else {
echo('Computer says no.');
}

Lamped
12-05-2010, 05:29 AM
Looks like I did something daft. That would send the email to the person who submitted the form. It's 5:30am and I can't sleep...


// This be send_form_email.php

if (!$_POST['email']) {
echo('Oh no! There\'s no email address!');
}

if (@mail(
'destination@email.address',
'Web form submit',
"
Web Form Email\n
From: {$_POST['first_name']} {$_POST['last_name']}\n
Address: (I'm sure you get the point here and can copy the line above...)

Lawn: ".implode(', ', $_POST['Lawn'])."\n
Irrigation: ".implode(', ', $_POST['Irrigation'])."\n
",
'From: '.$_POST['email']
)) {
echo('Sent');
} else {
echo('Computer says no.');
}

k, that's less stupid.

06f150
12-05-2010, 06:22 AM
K, that's a start, but it still looks like greek to me lol...



When the Sumbit button is click, it should only be sending an email to me, is that how you got it set up?


Also I changed the Lawn and irrigation to include [] at the end


Could you do a few more tags of it so I could see the pattern?

Also some of the fields need to be required, how would that go in ?

Lamped
12-05-2010, 11:13 AM
K, that's a start, but it still looks like greek to me lol...



When the Sumbit button is click, it should only be sending an email to me, is that how you got it set up?


Also I changed the Lawn and irrigation to include [] at the end


Could you do a few more tags of it so I could see the pattern?

Also some of the fields need to be required, how would that go in ?



// This be send_form_email.php

// Form validation, the bad but simple way:
if (!$_POST['email']) {
die('Oh no! There\'s no email address!');
}

if (!$_POST['city']) {
die('Oh no! There\'s no city!');
}

if (@mail(
'destination@email.address',
'Web form submit',
"
Web Form Email\n
From: {$_POST['first_name']} {$_POST['last_name']}\n
Address: {$_POST['address']}\n
City: {$_POST['city']}\n
Zip: {$_POST['zip_code']}\n

I am so not typing all these out for you :p

Lawn: ".implode(', ', $_POST['Lawn'])."\n
Irrigation: ".implode(', ', $_POST['Irrigation'])."\n
",
'From: '.$_POST['email']
)) {
echo('Sent');
} else {
echo('Computer says no.');
}

Lamped
12-05-2010, 11:33 AM
Right, sorry, I was interruped as I clicked send. In the first few lines you'll see 2 examples of form validation, this is not good or proper validation, but proper validation is a can of worms. You help you understand what !$_POST['value'] means: http://php.net/manual/en/language.types.boolean.php - read the section on "converting to boolean", you'll notice unset and blank strings both convert to false, ! flips it to true to match the "if".

{$_POST['value']} is a way of putting a complex variable in a "" quoted string.

Line 13 contains 'destination@email.address' - change this to your actual email address.

06f150
12-08-2010, 06:23 AM
Right, sorry, I was interruped as I clicked send. In the first few lines you'll see 2 examples of form validation, this is not good or proper validation, but proper validation is a can of worms. You help you understand what !$_POST['value'] means: http://php.net/manual/en/language.types.boolean.php - read the section on "converting to boolean", you'll notice unset and blank strings both convert to false, ! flips it to true to match the "if".

{$_POST['value']} is a way of putting a complex variable in a "" quoted string.

Line 13 contains 'destination@email.address' - change this to your actual email address.

I got everything figured out now, up and running just like it should!


Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum