0

So this is my php code:

Send-email.php

<?php 
$ToEmail = 'email@mail.com';
$EmailSubject = 'Request Lawn Mowing Quote';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader. = "Reply-To: ".$_POST["email"]."\r\n";
$mailheader. = "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";

$MESSAGE_BODY. = "<br>Country/State: ".$_POST["states"]."";
$MESSAGE_BODY. = "<br>Suburb: ".$_POST["suburb"]."";
$MESSAGE_BODY. = "<br>Unit/Street No.: ".$_POST["unit"]."";
$MESSAGE_BODY. = "<br>Street Name: ".$_POST["street"]."";
$MESSAGE_BODY. = "<br>Phone: ".$_POST["phone"]."";
$MESSAGE_BODY. = "<br> Email: ".$_POST["email"]."";
$MESSAGE_BODY. = "<br> Service: ".$_POST["service"]."";
$MESSAGE_BODY. = "<br> Comment: ".nl2br($_POST["comment"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");
?>

Message was sent successfully! <a href="index.html">Go back</a>

and html:

<form method="POST" action="send-email.php">
    <p>
        <label for="name">Name *</label>
        <input type="text" size="40" id="name" name="name" />
    </p>
    <p>
        <label for="state">Country / State *</label>
        <select id="states" name="states">
            <option value="Australian Capital Territory">Australian Capital Territory</option>
            <option value="New South Wales">New South Wales</option>
            <option value="Victoria">Victoria</option>
            <option value="Quensland">Quensland</option>
            <option value="South Australia">South Australia</option>
            <option value="Western Australia">Western Australia</option>
            <option value="Tasmania">Tasmania</option>
            <option value="Northern Australia">Northern Australia</option>
        </select>
    </p>
    <p>
        <label>Suburb *</label>
        <input type="text" name="suburb" size="40" />
    </p>
    <p>
        <label>Unit / Street No *</label>
        <input type="text" name="unit" size="40" />
    </p>
    <p>
        <label>Street Name *</label>
        <input type="text" name="street" size="40" />
    </p>
    <p>
        <label>Preferred Phone *</label>
        <input type="text" name="phone" size="40" />
    </p>
    <p>
        <label>Email *</label>
        <input type="text" name="email" size="40" />
    </p>
    <p><strong>Please tick the service you require *</strong>
    </p>
    <p>
        <label class="label-checkbox">
            <input type="checkbox" name="service" value="Mowing & Slashing, Workcover & Insurance Jobs"
            size="40" />Mowing & Slashing, Workcover & Insurance Jobs</label>
    </p>
    <p>
        <label class="label-checkbox">
            <input type="checkbox" name="service" value="Ride on Mowing" size="40"
            />Ride on Mowing</label>
    </p>
    <br />
    <br />
    <br />
    <p>
        <label class="label-checkbox">
            <input type="checkbox" name="service" value="Gardening, Weeding, Clean Up of Overgrown Gardens, Spraying, Mulch, Vegetable Beds"
            size="40" />Gardening, Weeding, Clean Up of Overgrown Gardens, Spraying, Mulch, Vegetable
            Beds</label>
    </p>
    <br />
    <br />
    <p>
        <label class="label-checkbox">
            <input type="checkbox" name="service" value="Rubbish Removal" size="40"
            />Rubbish Removal</label>
    </p>
    <br />
    <p>
        <label class="label-checkbox">
            <input type="checkbox" name="service" value="Single Storey Gutter Cleaning"
            size="40" />Single Storey Gutter Cleaning</label>
    </p>
    <br />
    <p>
        <label class="label-checkbox">
            <input type="checkbox" name="service" value="Double Storey Gutter Cleaning"
            size="40" />Double Storey Gutter Cleaning</label>
    </p>
    <br />
    <p>
        <label class="label-checkbox">
            <input type="checkbox" name="service" value="Pruning & Hedge Trimming, Small Trees/Shrubs Pruned & Removed, Chainsaw Jobs"
            size="40" />Pruning & Hedge Trimming, Small Trees/Shrubs Pruned & Removed, Chainsaw
            Jobs</label>
    </p>
    <br />
    <p>
        <label class="label-checkbox">
            <input type="checkbox" name="service" value="Lawn Care, Coring, Vertimowing, Dethatching"
            size="40" />Lawn Care, Coring, Vertimowing, Dethatching</label>
    </p>
    <br />
    <p>
        <label class="label-checkbox">
            <input type="checkbox" name="service" value="Landscaping, New Lawns, Irrigation, Planting, Artificial Turf"
            size="40" />Landscaping, New Lawns, Irrigation, Planting, Artificial Turf</label>
    </p>
    <br />
    <p>
        <label class="label-checkbox">
            <input type="checkbox" name="service" value="Flye Cleaning, Snow Removal, Water Blasting (NZ Only), Trash Packs (TAS only)"
            size="40" />Flye Cleaning, Snow Removal, Water Blasting (NZ Only), Trash Packs (TAS
            only)</label>
    </p>
    <br />
    <br />
    <p>
        <label>Comments *</label>
        <textarea cols="50" rows="5" type="text" id="comment"
        name="comment"></textarea>
    </p>
    <p>
        <button type="submit">Request A Free Quote</button>
        <button type="reset">Cancel</button>
    </p>
</form>

This works but not all fields are being sent to the recipient. Like the checkbox field (services), name, country/state, suburb, street name and comment. Please help me figure out what's missing or wrong in my code. Thanks.

4

2 回答 2

2

Note that checkboxes can be an array. You should use name="service[]" in your checkbox fields instead of name="service". Then, when interpolating the input into the email, use implode(', ', $_POST['service']); since it will be an array.

What happens when you print_r($_POST);?

于 2013-08-30T06:35:10.613 回答
0

First of all check

echo "<pre>";
print_r($_POST);
echo "<pre>";

And then check you must define

$MESSAGE_BODY = "";

If you not define it through error Undefined variable $MESSAGE_BODY

And Last check

echo "<pre>";
print_r($MESSAGE_BODY);
echo "<pre>";

Edit Add this just upper of mail();

$mailheader  = "MIME-Version: 1.0" . "\r\n";
$mailheader .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
于 2013-08-30T06:41:23.533 回答