Forum Moderators: coopster

Message Too Old, No Replies

Contact Form Not Working

         

Jamier101

10:35 pm on Mar 18, 2011 (gmt 0)

10+ Year Member



I have written a contact form but I don't seem to be able to get it to work and was therefore wondering if someone could please check it over for me.

Contact Form
 <form method="POST" action="sendmail.php">
Name:<br />
<input type="text" name="Name"><br />
Tel:<br />
<input type="text" name="Tel"><br />
E-mail:<br />
<input type="text" name="email"><br />
WeddingDate:<br />
<input type="text" size="25" name="date"><a href="javascript:NewCal('date','ddmmyyyy')">
<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a><br />
Comment:<br />
<textarea name="Comment" cols="50" rows="8"></textarea><br />
<input type="submit" name="submit" value="Submit">
</form>


sendmail.php
<?php

$name = $_GET['name'];
$tel = $_GET['tel'];
$email = $_GET['email'];
$date = $_GET['date'];
$message = $_GET['message'];

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $tel;
$Body .= "\n";
$Body .= "Wedding Date: ";
$Body .= $date;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";

$success = mail("me@myemail.com", "Enquiry", $body, "From: $email" );

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=success.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
}

?>

LifeinAsia

10:51 pm on Mar 18, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Can you post any error messages or other indications about what's not working?

Jamier101

11:02 pm on Mar 18, 2011 (gmt 0)

10+ Year Member



After stripping the code down and starting again I am now getting e-mails although I'm not getting any of the message in the body.

<?php

$name = $_GET['name'];
$tel = $_GET['tel'];
$email = $_GET['email'];
$date = $_GET['date'];
$enquiry = $_GET['message'];

$to = 'me@myemail.com';
$subject = 'Enquiry';
$body = '$enquiry';

mail($to, $subject, $body, "From: $email");

print "<meta http-equiv=\"refresh\" content=\"0;URL=success.php\">";

?>

Jamier101

11:04 pm on Mar 18, 2011 (gmt 0)

10+ Year Member



I probably should have posted the amended HTML code as well:

<form method="POST" action="sendmail2.php">
Name:<br />
<input type="text" name="Name"><br />
Tel:<br />
<input type="text" name="Tel"><br />
E-mail:<br />
<input type="text" name="email"><br />
WeddingDate:<br />
<input id="date" type="text" size="25" name="date"><a href="javascript:NewCal('date','ddmmyyyy')">
<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a><br />
Comment:<br />
<textarea name="enquiry" cols="50" rows="8"></textarea><br />
<input type="submit" name="submit" value="Submit">
</form>

rainborick

3:26 am on Mar 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You've got the name attribute wrong in your <form>, according to your script.


<textarea name="enquiry" cols="50" rows="8">

should be:

<textarea name="message" cols="50" rows="8">

Matthew1980

9:57 am on Mar 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Jamier101,

Your form:- (Your stipulating POST as method!)
<form method="POST" action="sendmail.php">

Your processing script:- (Your using $_GET's)
//Change these to $_POST

$name = $_GET['name'];
$tel = $_GET['tel'];
$email = $_GET['email'];
$date =$_GET['date'];
$enquiry = $_GET['message'];
//ensure that you have these the right way around as rainborick points out ;)

$to = 'me@myemail.com';
$subject = 'Enquiry';
$body = '$enquiry';

mail($to, $subject, $body, "From: $email");

//use a header call here to redirect users
header("Location: the_page_you_want_to_use.php");
exit;
?>

Hope that makes sense anyway!

Cheers,
MRb