How can I style an e-mail that's sent from a contact form?
I'd like to place it into nice tables with some decent styling. My front-end is just a HTML page that the user fills out a form. The form, upon submit, calls this PHP page to send the data. I have all of that portion working perfectly.
Now, I'd just like to style how the e-mail looks to the person receiving the e-mail since right now it's all just text & data.
My current PHP code is:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "email@email.com";
$email_subject = "TEST - NO STYLE JUST DATA- Product Research Request";
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['ProductMgr']) ||
!isset($_POST['ProductDesc'])||
!isset($_POST['email'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$ProductMgr = $_POST['ProductMgr']; // required
$email_from = $_POST['email']; // required
$ProductDesc = $_POST['ProductDesc']; // required
$ProjLaunchDate = $_POST['ProjLaunchDate']; // required
$ProdCat = $_POST['ProdCat']; // required
$ProdSubCat = $_POST['ProdSubCat']; // required
$SuggVendor = $_POST['SuggVendor']; // required
$VPartNum = $_POST['VPartNum']; // required
$EstLandCost = $_POST['EstLandCost']; // required
$EstRetail = $_POST['EstRetail']; // required
$GMPercent = $_POST['GMPercent']; // required
$GMDollar = $_POST['GMDollar']; // required
$ForeUSales = $_POST['ForeUSales']; // required
$ForeDSales = $_POST['ForeDSales']; // required
$WholesalePot = $_POST['WholesalePot']; // required
$CompProdPrice = $_POST['CompProdPrice']; // required
$CompCompany = $_POST['CompCompany']; // required
$SampleAvail = $_POST['SampleAvail']; // required
$ProdDims = $_POST['ProdDims']; // required
$ProdColors = $_POST['ProdColors']; // required
$EstProdWeight = $_POST['EstProdWeight']; // required
$Features = $_POST['Features']; // required
$AMLBenefits = $_POST['AMLBenefits']; // required
$ProBenefits = $_POST['ProBenefits']; // required
$Restrictions = $_POST['Restrictions']; // required
$GKS = $_POST['GKS'];
$ProdMgr2 = $_POST['ProdMgr2']; // required
$ProdDesc2 = $_POST['ProdDesc2']; // required
$PossVend = $_POST['PossVend']; // required
$ProjReTime = $_POST['ProjReTime']; // required
$EstLandCost2 = $_POST['EstLandCost2']; // required
$ProtoExpDate = $_POST['ProtoExpDate']; // required
$ProdExpDate = $_POST['ProdExpDate']; // required
$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 />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Product Manager: ".clean_string($ProductMgr)."\n";
$email_message .= "Product Description: ".clean_string($ProductDesc)."\n";
$email_message .= "Projected Launch Date: ".clean_string($ProjLaunchDate)."\n";
$email_message .= "Product Category: ".clean_string($ProdCat)."\n";
$email_message .= "Product Subcategory: ".clean_string($ProdSubCat)."\n";
$email_message .= "Suggested Vendor: ".clean_string($SuggVendor)."\n";
$email_message .= "Vendor Part Number: ".clean_string($VPartNum)."\n";
$email_message .= "Estimated Landed Cost: ".clean_string($EstLandCost)."\n";
$email_message .= "Estimated Retail: ".clean_string($EstRetail)."\n";
$email_message .= "Gross Margin %: ".clean_string($GMPercent)."\n";
$email_message .= "Gross Margin $: ".clean_string($GMDollar)."\n";
$email_message .= "Forecasted Unit Sales: ".clean_string($ForeUSales)."\n";
$email_message .= "Forecasted Dollar Sales: ".clean_string($ForeDSales)."\n";
$email_message .= "Wholesale Potential: ".clean_string($WholesalePot)."\n";
$email_message .= "Competition Product & Price: ".clean_string($CompProdPrice)."\n";
$email_message .= "Competitor Company: ".clean_string($CompCompany)."\n";
$email_message .= "Sample Available: ".clean_string($SampleAvail)."\n";
$email_message .= "Product Dimensions: ".clean_string($ProdDims)."\n";
$email_message .= "Product Colors: ".clean_string($ProdColors)."\n";
$email_message .= "Estimated Product Weight: ".clean_string($EstProdWeight)."\n";
$email_message .= "Features: ".clean_string($Features)."\n";
$email_message .= "Benefits to AML: ".clean_string($AMLBenefits)."\n";
$email_message .= "Benefits to Pro Customers: ".clean_string($ProBenefits)."\n";
$email_message .= "Any Restrictions: ".clean_string($Restrictions)."\n";
$email_message .= "GKS Approval To Go: ".clean_string($GKS)."\n";
$email_message .= "Product Manager: ".clean_string($ProdMgr2)."\n";
$email_message .= "Product Description: ".clean_string($ProdDesc2)."\n";
$email_message .= "Possible Vendors: ".clean_string($PossVend)."\n";
$email_message .= "Projected Research Time: ".clean_string($ProjReTime)."\n";
$email_message .= "Estimated Landing Cost: ".clean_string($EstLandCost2)."\n";
$email_message .= "Prototypes Expected Date: ".clean_string($ProtoExpDate)."\n";
$email_message .= "Production Expected Date: ".clean_string($ProdExpDate)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
}
header("Location: ThankYou.html"); //Redirect to Thank You HTML page after email is sent
?>