发送购物车的PHP电子邮件

时间:2013-05-22 03:59:42

标签: php email cart

我已经写了一份表格,在表格完成后会根据发件人的订单向地址发送电子邮件。

目前,我编写了php,它列出了电子邮件中的所有项目,无论匹配输入的值是否已更改(假设他们已经订购了5 x项目1和0x项目2,电子邮件仍会显示两者。)

有没有办法只发送包含已订购商品的电子邮件?

这是我的代码。

    $email_subject = "New Order Form Submitted";

    $companyName = $_POST['companyName']; //required
    $companyAddress = $_POST['companyAddress']; //required
    $datepicker = $_POST['datepicker']; //required
    $taxAmount = $_POST['taxAmount']; //required
    $phoneNumber = $_POST['phoneNumber']; //required
    $emailAddress = $_POST['emailAddress']; //required

    $comments = $_POST['comments'];
    $subtotalAmt = $_POST['subtotalAmt'];
    $tax = $_POST['tax'];
    $totalAmt = $_POST['totalAmt'];

    $WC001 = $_POST['WC001'] //Natural Tray
    $WC300 = $_POST['WC300'] //Dark Brown Tray


    $formcontent = "Order Details Below.  \n\n"; 

    $formcontent .= "Company Name: $companyName \n";
    $formcontent .= "Company Address: $companyAddress \n";
    $formcontent .= "Email Address: $emailAddress \n";
    $formcontent .= "Delivery Date Requested: $datepicker \n";
    $formcontent .= "Phone Number: $phoneNumber \r\n";

    $formcontent .= "WC001 Amount Ordered: $WC001 \n";
    $formcontent .= "WC300 Amount Ordered: $WC300 \n";
    $formcontent .= "Tax: $taxAmount (In decimal value. 1.0 means 100%) \n";
    $formcontent .= "Subtotal: $subtotalAmt \n";
    $formcontent .= "======================================= \n";
    $formcontent .= "Total Due: $totalAmt \r\n";
    $formcontent .= "Comments/Instructions: $comments \r\n";

    // create email headers
    $headers = 'From: '.$emailAddress."\r\n".
    'Reply-To: '.$emailAddress."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $formcontent, $headers);  

1 个答案:

答案 0 :(得分:1)

更改这些行:

$formcontent .= "WC001 Amount Ordered: $WC001 \n";
$formcontent .= "WC300 Amount Ordered: $WC300 \n";

对此:

if($WC001 > 0)
    $formcontent .= "WC001 Amount Ordered: $WC001 \n";
if($WC300 > 0)
    $formcontent .= "WC300 Amount Ordered: $WC300 \n";