1

I have recently constructed a form (see below) and i managed to write a php script where i set up the mail to be sent when i press the submit button from the form. The problem is that in php script in the $message variable the only things that are sent by email are the string and not the variables such as $name, $customer_number etc.

Could anybody be kind enough to point out the error to me please?

The form:

<form name="bookingForm" method="post" action="send_dates.php">
<table border="0" cellspacing="1" cellpadding="2">

<tr>
<td>Booking From</td>
<td>:</td>
<td><input name="fromDate" id="fromDate" size="20"></td>

<td>To</td>
<td>:</td>
<td><input name="toDate" id="toDate" size="20"></td>
</tr>

<tr>
    <td>Name</td>
    <td>:</td>
    <td><input name="name" id="name" size="30"></td>
</tr>

<tr>
    <td width="20px">Telephone</td>
    <td>:</td>
    <td><input name="customer_telephone" id="customer_telephone" size="30"></td>
</tr>

<tr>
    <td width="20px">Email</td>
    <td>:</td>
    <td><input name="customer_email" id="customer_email" size="30"></td>
</tr>

<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" value="Submit" onClick="document.getElementById('ResetForm').click();">
    <input type="reset" name="ResetForm" id="ResetForm" value="Reset"></td>
</tr>
</table>
    </form>

PHP script send_data:

<?php
$name = $_POST["name"];
$fromDate = $_POST["fromDate"];
$toDate = $_POST["toDate"];
$email = $_POST["customer_email"];
$telephone = $_POST["customer_telephone"];

// Mail of recievers
$to = "[email protected]";

// Contact subject
$subject ="Reservation Enquiry from $name";

// Details
$message="
From: $name
Email: $customer_email
Telephone: $customer_telephone
--------------------------------------------------------------
Reservation date from: $fromDate to: $toDate ";

// Mail of sender
$mail_from="$customer_email";

$rev = mail($to,$subject,$message);

if($rev) {
    echo 'booking request has been sent!';
}
else {
    echo 'something has gone wrong. Please try again!';
} ?>
1
  • What's the result when you do a var_dump on $_POST? Commented Jul 26, 2012 at 16:54

3 Answers 3

6

You're defining the variables as $email and $telephone, but using them as $customer_email and $customer_telephone, respectively.

Update the name usage in either area and you should be set.

Sign up to request clarification or add additional context in comments.

1 Comment

what a stupid mistake, i kept putting in the input box names instead of the variables :-S
1

You have a wrong variable name. Replace

From: $name
Email: $customer_email
Telephone: $customer_telephone

with

From: $name
Email: $email
Telephone: $telephone

Comments

0

if you have register_globals off [likely to be thhis way] you'd better use $telephone instead of $customer_telephone in your $message

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.