Hi, I have a form that I tweaked from a free online form I found (not very well versed in PHP, and definitely not in PHP5 yet!). When you click the submit button, rather than sending the email and posting the thank you message, it just takes you to the sender.php 'page' which is blank. Here is the HTML code:
HTML Code:
<form name="dform" action="sender.php" method="post">
<table>
<tr>
<td>
email : <input type="text" name="email_from" style="width:215px; height:15px; overflow:hidden; background-color:#ffffff; border:solid; border-width:1px; border-color:#6986B7; font-family: Arial, Helvetica, sans-serif; color:#6986B7; font-size:14; letter-spacing:1px;" />
child’s age: years <select name="age_years">
<option value="0" style="background-color:#ffffff;">0</option>
<option value="1" style="background-color:#ffffff;">1</option>
<option value="2" style="background-color:#ffffff;">2</option>
<option value="3" style="background-color:#ffffff;">3</option>
<option value="4" style="background-color:#ffffff;">4</option>
<option value="5" style="background-color:#ffffff;">5</option>
</select>
months <select name="age_months">
<option value="0" style="background-color:#ffffff;">0</option>
<option value="1" style="background-color:#ffffff;">1</option>
<option value="2" style="background-color:#ffffff;">2</option>
<option value="3" style="background-color:#ffffff;">3</option>
<option value="4" style="background-color:#ffffff;">4</option>
<option value="5" style="background-color:#ffffff;">5</option>
<option value="6" style="background-color:#ffffff;">6</option>
<option value="7" style="background-color:#ffffff;">7</option>
<option value="8" style="background-color:#ffffff;">8</option>
<option value="9" style="background-color:#ffffff;">9</option>
<option value="10" style="background-color:#ffffff;">10</option>
<option value="11" style="background-color:#ffffff;">11</option>
<option value="12" style="background-color:#ffffff;">12</option>
</select>
</td>
<td>
<input type="image" src="images/hb-learnmorebutton.png" value="submit" name="submit" style="border:none; background:#ffffff; margin-left:10px;" />
</td></tr></table>
</form>
And here is the PHP code from sender.php:
PHP Code:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "kate@madisonandmi.com";
$email_subject = "Contact Form Submission";
function died($error) {
// your error code can go here
echo "Oops!";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please fix these errors and try again.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['email']) ||
!isset($_POST['age_years']) ||
!isset($_POST['age_months'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$email_from = $_POST['email']; // required
$telephone = $_POST['age_years']; // required
$comments = $_POST['age_months']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$age_years)) {
$error_message .= 'Please enter your childs age in years.<br />';
}
if(strlen($age_months) < 2) {
$error_message .= 'Please enter your childs age in months.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Years: ".clean_string($age_years)."\n";
$email_message .= "Months: ".clean_string($age_months)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<link href="style.css" rel="stylesheet" type="text/css">
<body class="center">
Thank you for your interest in haepi bean! <br />We will be in touch soon!
<?php
}
?>
Bookmarks