简体   繁体   中英

Sending PHP email of shopping cart

I've written a form that sends an email to an address after a form is completed with what the sender's order will be.

Currently, I've written the php so that it lists all the items in the email regardless of whether the value of the matching input has changed (lets say they've ordered 5 x item 1, and 0x item 2, the email will still show both).

Is there a way to just send the email with just the items that have been ordered?

here's a my code.

    $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);  

Change these lines:

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

To this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM