样式化从联系表单发送的电子邮件

时间:2013-02-22 17:41:47

标签: php forms styles

如何设置从联系表单发送的电子邮件的样式?

我想把它放在漂亮的桌子上,有一些不错的造型。我的前端只是一个用户填写表单的HTML页面。表单在提交后调用此PHP页面来发送数据。我的所有部分都完美无缺。

现在,我想简单地说明电子邮件对接收电子邮件的人的看法,因为现在它只是文本&数据

我目前的PHP代码是:

<?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
?>

1 个答案:

答案 0 :(得分:0)

邮件正文的开头部分以下面一行代码开头:

  

$ email_message =“表格详情如下。\ n \ n”;

然后消息的其余部分仅仅是以“label:$ value”的格式在新行上添加每个值,以:

开头
  

$ email_message。=“产品经理:”。makean_string($ ProductMgr)。“\ n”;

结尾
  

$ email_message。=“预计生产日期:”。makean_string($ ProdExpDate)。“\ n”;

假设您想要在表中使用所有这些,您可以在字段分配之前或之后添加一行,或者将其附加/附加到上述语句中。一个非常基本的例子:

$email_message .="<table>";
$email_message .= "Product Manager: ".clean_string($ProductMgr)."\n";
.
.
.
$email_message .= "Production Expected Date: ".clean_string($ProdExpDate)."\n";
$email_message .= "</table>";

根据需要添加标题,行和列,以便在您希望进入表格路径时获得所需的布局。

基本上你只是将html添加到$ email_message。您可能会发现更容易让html首先运行,然后使用它作为模板,以便您需要将$ email_message字符串连接起来以获得相同的结果。

祝你好运。