Form to Email Problem

Hi Guys,

Im trying to created a a simple form to email, having use it on my contact page it works fine, however I’m trying to modify it into a simple booking form with extra fields including telephone, check in/out dates etc. Its on this site:


However, Ive added extra vaiable e.g. “$checkin” and the form sends fine, although now the sender’s email address changes to (my host) instead of the email entered by the person using the form. I have pasted the code below, I would be REALLY grateful if someone could help. Many Thanks Paul :slight_smile:

$email_address = “”; //This should be changed to your email address.
$subject_prefix = "Shalom House Booking Request | "; //This will be the subject prefix of all emails. default "Website Contact - User Subject

// — Do not modify below —
//Collects varibles from previous page.

$name = $_POST['name'];
$email = $_POST['email'];
$subject = $subject_prefix . $_POST['subject'];
$telephone = $_POST['telephone'];
$checkin = $_POST['checkin'];

//This part should prevent malicous doings.
//Most servers are setup in such a way that this section is not needed but its a good security precaution to have.
$from = urldecode($email);
if (eregi(“\r”,$from) || eregi("
print “Malformed Headers were detected.”;
//This part sends the email to you.
mail($email_address, $subject, $telephone, $checkin, “From: $name <$email>
X-Mailer: Simple PHP Contact Form 1.0 (”);

//Redirects to sent.htm
header(“Location: booking_received.html”)

?> [/COLOR]


<form action=“send_booking.php” method=“post”>
Name:<br><input type=“text” size=‘37’ name=‘name’><br>
E-Mail:<br><input type=‘text’ size=‘37’ name=‘email’><br>
Subject:<br><input type=‘text’ size=‘37’ name=‘subject’><br>
Telephone:<br><input type=‘text’ size=‘37’ name=‘telephone’><br>
Check In:<br><input type=‘text’ size=‘37’ name=‘checkin’><br>
<input type=‘submit’ class=“submit-button” value=“Submit”>

plan of using captcha as well else you will get lots of emails,offcourse spam

Or dont, since $email is transformed into $from halfway through the script, and $email_address is set in the very first line to be the delivery address, not a form field.

also try changing




The email address coming from the form is being assigned here in your script

$email = $_POST['email'];

into \r
before the X-Mailer and see if it fixes the problem. Your header might be being discarded as malformed.

Okay… I see what you’ve done now…
Mail takes 3-5 parameters. You’ve modified the mail call and moved the parameters around.

Try THIS instead.

mail($email_address, $subject, $telephone."\\r\
".$checkin, "From: $name <$email>\
X-Mailer: Simple PHP Contact Form 1.0 (");

Well, it really depends on what sort of learner you are, and what programming experience you have.

For example, look at the mail() documentation page. Does this make sense to you? Or do you look at the top box and go ‘uh… technical jargon. huh?’.

Compare your initial post, my fix, and that mail documentation, and see if you can follow where your error occurred and why (both why you had the error, and how/why the fix works).

My default ‘how do i learn free online…’ answer is

If you’ve got a good base in HTML/CSS, you’ll find it easier to insert the code into the HTML, rather than building the HTML using code.

Hi StarLion,

Thanks for you reply, although I tried you suggestion and it didnt work. Do you have any other suggestions?

Many thanks,


oooops :blush: you’re right - my mistake - sorry.

Hi Guys,

Thank you for the help, especially Star Lion, much appreciated. I’m really struglling with PHP. Does anyone know of any good online resources to quickly learn the basics, as I know how to build a form and site easily with CSS but as I downloaded the php form I’m just doing guesswork.

I can see how the forms work to a certain degree but fixing errors/modification is my weakness.

P.S I got the form to eventually work.

Many Thanks,:slight_smile:


you can append the email address by ‘<’.$email_address.‘>’
I think this is ur problem…
otherwise send the error message u got…for better clarification…

Thanks for the help, I do have a good base of XHTML and CSS. I find it easy to hand code, but with PHP etc im bluffing my way through it. I can see how the mail works, it collects the variables set at the begining of the script and used from the “labels” in the form. But I know at the minitue I wouldnt be able to write a contact form from scratch.

I will go throught the W3C tutorials, I have briefly looked at them before. Do you know how I could add CAPTHA to the form? Do people write this code themselves or dot hey simply copy and paste to protect from Spam?

Thanks Again