Jump to content

.London Domains - £4
Photo

PHP mail form outputting html email


  • Please log in to reply
No replies to this topic

#1 juicylemons

juicylemons
  • Member
  • Newbie
  • 9 posts

Posted 15 November 2018 - 18:15

Hi All,

 

I have a mail form that is submitted by a user of our website that alows multiple drops down selections and free text fields. when submitted I want the email it sends to be a html email so that I can make it look a lot more presentable. This is the PHP code:

<?php

if(isset($_POST['email'])) {


// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "dan@elastothane.com";
$email_subject = "Online Order submission";


function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}




// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['company_name']) ||
!isset($_POST['email']) ||
!isset($_POST['purchase_order']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}






$name = $_POST['name']; // required
$company_name = $_POST['company_name']; // required
$email_from = $_POST['email']; // required
$purchase_order = $_POST['purchase_order']; // not required
$comments = $_POST['comments']; // not required
$product1=$_POST['product1'];
$kit1=$_POST['kit1'];
$colour1=$_POST['colour1'];
$quantity1=$_POST['quantity1'];


$product2=$_POST['product2'];
$kit2=$_POST['kit2'];
$colour2=$_POST['colour2'];
$quantity2=$_POST['quantity2'];


$product3=$_POST['product3'];
$kit3=$_POST['kit3'];
$colour3=$_POST['colour3'];
$quantity3=$_POST['quantity3'];




$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';


if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}


$string_exp = "/^[A-Za-z0-9 .'-]+$/";


if(!preg_match($string_exp,$name)) {
$error_message .= 'The name you entered does not appear to be valid.<br />';
}


if(!preg_match($string_exp,$company_name)) {
$error_message .= 'The company name you entered does not appear to be valid.<br />';
}




if(strlen($comments) < 0) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';


}


if(strlen($error_message) > 0) {
died($error_message);
}


$email_message = "Order details \n\n";




function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}










$email_message .= "name: ".clean_string($name)."\n";
$email_message .= "company Name: ".clean_string($company_name)."\n";
$email_message .= "email: ".clean_string($email_from)."\n";
$email_message .= "purchase order: ".clean_string($purchase_order)."\n";
$email_message .= "comments: ".clean_string($comments)."\n";
$email_message .= "Product1: ".clean_string($product1)."\n";
$email_message .= "Kit1: ".clean_string($kit1)."\n";
$email_message .= "Colour1: ".clean_string($colour1)."\n";
$email_message .= "Quantity1: ".clean_string($quantity1)."\n";
$email_message .= "Product2: ".clean_string($product2)."\n";
$email_message .= "Kit2: ".clean_string($kit2)."\n";
$email_message .= "Colour2: ".clean_string($colour2)."\n";
$email_message .= "Quantity2: ".clean_string($quantity2)."\n";
$email_message .= "Product3: ".clean_string($product3)."\n";
$email_message .= "Kit3: ".clean_string($kit3)."\n";
$email_message .= "Colour3: ".clean_string($colour3)."\n";
$email_message .= "Quantity3: ".clean_string($quantity3)."\n";






// create email headers
$headers = 'From: '.$email_from."\r\n".


'Reply-To: '.$email_from."\r\n" .
'Cc: sales@lpultd.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>


<!-- include your own success html here -->


'<script>window.location.href = "http://www.elastothane.com/done2.htm";</script>';


<?php


}
?>




and this is the code that generates the drop downs etc:


<table width="1000" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
<tr><td width="1000" height="100" rowspan="2"><font face=verdana size=2 color="#000000">
<img src="pics/epos.jpg">
<br><br>
To place an order, please fill in the following form.<br><br>
Our daily order cut off is 1pm Monday to Thursday, and 12pm on Friday. All orders placed before the cut off will be shipped "next day" (UK Mainland) subject to availability. Should there be any problem with your order we will contact you as soon as possible.<br><br>


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


<table width="1000" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
<tr><td width="1000" height="50" rowspan="2"><font face=verdana size=2 color="#000000">
</td>
</tr>
</table>


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


<table width="100px">
<tr>
 <td valign="top">
  <label for="name">Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="name" maxlength="50" 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="50" 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="telephone">Purchase Order*<br></label>
 </td>
 <td valign="top">
  <input  type="text" name="purchase_order" maxlength="30" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="comments">Delivery Address / instructions*<br></label>
 </td>
 <td valign="top">
  <textarea  name="comments" maxlength="1000" cols="205" rows="6"></textarea>
 </td>
</tr>




<tr>
 <td valign="top">
<br><br>
<font face="verdana" size=1"" color="#393939">Please select the <b>1st</b> product you require:
<br>
<br>
<select name="product1" id="product_select">
<option>--select--</option>
<option>--PRIMERS--</option>
<option>Elastoprime 3550 metal primer</option>
<option>Elastoprime 3558 concrete primer</option>
<option>Elastoprime 3528 concrete primer</option>
<option> Isoprime 3922 intercoat primer</option>
<option>-----------------------------------------</option>
<option> </option>
<option>--POLYUREA--</option>
<option>Elastoline 6050</option>
<option>Elastoline 7065 5 second gel</option>
<option> </option>
<option>--SPECIAL ORDER ITEMS--</option>
<option>Elastoline 6060</option>
<option>Elastoline 6070</option>
<option>Elastoline 7065 5 second gel</option>
<option>Elastoline 7065 10 second gel</option>
<option>Elastoline 7065 15 second gel</option>




</select>


</td>
</tr>


<tr>
<td colspan="2">


<br>
<font face="verdana" size=1"" color="#393939">Please select the set/kit size you require:
<br>
<br>
<select name="kit1" id="product_select">
<option>--select--</option>
<option>444/450KG drum set (A&B)</option>
<option>32KG pail set (A&B)</option>
<option>12.5KG (Elastoprime 3558)</option>
<option>21.41KG (Elastoprime 3528)</option>
<option>12.5KG (Elastoprime 3550)</option>
<option>5KG (Isoprime 3922)</option>
<option>25KG (Isoprime 3922)</option>


</select>


</td>
</tr>


<tr>
<td colspan="2">


<br>
<font face="verdana" size=1"" color="#393939">Please select the colour you require:
<br>
<br>
<select name="colour1" id="product_select">
<option>--select--</option>
<option>Neutral</option>
<option>Black</option>
<option>Grey</option>
<option>-------------------------</option>
<option>No Colour - I'm a primer!</option>




</select>


</td>
</tr>




<tr>
<td valign="top">
<br><br>
<label for="quantity">Quantity Required</label>
</td>
</tr>
<tr>
<td valign="top">
<input type="text" name="quantity1" maxlength="30" size="30">
</td>
</tr>
<tr>
<td colspan="2">
<br><br>
<font face="verdana" size=1"" color="#393939">-------------------------------------------------------------------------------------------------
<br><br>


<tr>
<td colspan="2">
<font face="verdana" size=1"" color="#393939">Please select the 2nd<b>2nd</b> product you require:
</td></tr>


<tr>
<td>
<select name="product2"  id="product_select">
<option>--select--</option>
<option>--PRIMERS--</option>
<option>Elastoprime 3550 metal primer</option>
<option>Elastoprime 3558 concrete primer</option>
<option>Elastoprime 3528 concrete primer</option>
<option> Isoprime 3922 intercoat primer</option>
<option>-----------------------------------------</option>
<option> </option>
<option>--POLYUREA--</option>
<option>Elastoline 6050</option>
<option>Elastoline 7065 5 second gel</option>
<option> </option>
<option>--SPECIAL ORDER ITEMS--</option>
<option>Elastoline 6060</option>
<option>Elastoline 6070</option>
<option>Elastoline 7065 5 second gel</option>
<option>Elastoline 7065 10 second gel</option>
<option>Elastoline 7065 15 second gel</option>




</select>


</td>




</tr>
<tr>




<td colspan="2">


<br>
<font face="verdana" size=1"" color="#393939">Please select the set/kit size you require:
<br>
<select name="kit2" id="product_select">
<option>--select--</option>
<option>444/450KG drum set (A&B)</option>
<option>32KG pail set (A&B)</option>
<option>12.5KG (Elastoprime 3558)</option>
<option>21.41KG (Elastoprime 3528)</option>
<option>12.5KG (Elastoprime 3550)</option>
<option>5KG (Isoprime 3922)</option>
<option>25KG (Isoprime 3922)</option>




</select>


</td>


</tr>
<tr>




<td colspan="2">


<br>
<font face="verdana" size=1"" color="#393939">Please select the colour you require:
<br>
</td>
</tr>
<tr>
<td>
<select name="colour2" id="product_select">
<option>--select--</option>
<option>Neutral</option>
<option>Black</option>
<option>Grey</option>
<option>-------------------------</option>
<option>No Colour - I'm a primer!</option>




</select>


</td>
</tr>
<tr>
<td valign="top">
<br><br>
<label for="quantity">Quantity Required</label>
</td>
</tr>
<tr>
<td valign="top">
<br>
<input type="text" name="quantity2" maxlength="30" size="30">
</td>
</tr>
<tr>
<td colspan="2">
<br><br>
<font face="verdana" size=1"" color="#393939">-------------------------------------------------------------------------------------------------
<br><br>
</td></tr>


<tr><td colspan="2">


<font face="verdana" size=1"" color="#393939">Please select the <b>3rd</b> product you require:
</td>
</tr>


<tr>
<td>
<select name="product3" id="product_select">
<option>--select--</option>
<option>--PRIMERS--</option>
<option>Elastoprime 3550 metal primer</option>
<option>Elastoprime 3558 concrete primer</option>
<option>Elastoprime 3528 concrete primer</option>
<option> Isoprime 3922 intercoat primer</option>
<option>-----------------------------------------</option>
<option> </option>
<option>--POLYUREA--</option>
<option>Elastoline 6050</option>
<option>Elastoline 7065 5 second gel</option>
<option> </option>
<option>--SPECIAL ORDER ITEMS--</option>
<option>Elastoline 6060</option>
<option>Elastoline 6070</option>
<option>Elastoline 7065 5 second gel</option>
<option>Elastoline 7065 10 second gel</option>
<option>Elastoline 7065 15 second gel</option>
</select>


</td>
</tr>


<tr>
<td colspan="2">


<br>
<font face="verdana" size=1"" color="#393939">Please select the set/kit size you require:
</td>
</tr>


<tr>
<td>
<select name="kit3" id="product_select">
<option>--select--</option>
<option>444/450KG drum set (A&B)</option>
<option>32KG pail set (A&B)</option>
<option>12.5KG (Elastoprime 3558)</option>
<option>21.41KG (Elastoprime 3528)</option>
<option>12.5KG (Elastoprime 3550)</option>
<option>5KG (Isoprime 3922)</option>
<option>25KG (Isoprime 3922)</option>


</select>


</td>
</tr>


<tr>
<td colspan="2">


<br>
<font face="verdana" size=1"" color="#393939">Please select the colour you require:<br>
<select name="colour3" id="product_select">
<option>--select--</option>
<option>Neutral</option>
<option>Black</option>
<option>Grey</option>
<option>-------------------------</option>
<option>No Colour - I'm a primer!</option>




</select>


</td>
</tr>


<tr>
<td valign="top">
<br><br><label for="quantity">Quantity Required</label>
</td>
</tr><tr>
<td valign="top">
<br><input type="text" name="quantity3" maxlength="30" size="30">
</td>
</tr>
<tr>
<td colspan="2">
<br><br>
<font face="verdana" size=1"" color="#393939">-------------------------------------------------------------------------------------------------
<br><br>
</td></tr>


<tr>
 <td colspan="2" style="text-align:center">
<br>
<br>
<br>
  <p class="submit">
<input type="submit" value="Submit">




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

Edited by Renaissance-Design, 15 November 2018 - 21:03.
Code formatting, people. PLEASE.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users