I always have a problem with forms being emailed for things like reservations, bookings, purchasing items, etc.
What if a person submits the form and then realizes they made a mistake two days later?
They fill it out again. Did the recipient see the 'correct' email? What if the recipient was on vacation? What if the second email ended up in a filtered folder?
Doing business that way is really a bad idea.
Your customers register for free and create a profile or account. Both the customer AND the business person see the same information at the same time. Any changes, corrections, cancellations, partial billing, etc. is handled by the scripting/database programs.
Email only used for brief confirmations or messages to let both parties know that the account needs to be looked at.
<?php if (isset($_POST['formsent']) && $_POST['formsent'] == "Sent"){ if (!isset($_POST['email_address']) || strlen($_POST['email_address'])<1){ $errors[] = "Email Field is Required. <BR>";$_POST['email_address'] = '';} if (!isset($_POST['EventType']) || strlen($_POST['EventType'])<1){ $errors[] = "Event Type is Required. <BR>";$_POST['EventType'] = '';} if (!isset($_POST['FoodType']) || strlen($_POST['FoodType'])<1){ $errors[] = "Food Type is Required. <BR>";$_POST['FoodType'] = '';} if (!isset($_POST['date']) || strlen($_POST['date'])<1){ $errors[] = "Date is Required. <BR>";$_POST['date'] = '';} if (!isset($_POST['name']) || strlen($_POST['name'])<1){ $errors[] = "Name is Required. <BR>";$_POST['name'] = '';}
if (count($errors) == 0){ ini_set("SMTP", "mail.domain.com"); ini_set("sendmail_from", "youremail@domain.com"); ini_set("smtp_port", "25");
$to = 'youremail@domain.com' ;
$subject = 'Event Booking'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = "<table><tr><td>Name</td><td>".$_POST['name']."</td></tr> <tr><td>E-Mail</td><td>".$_POST['email_address']."</td></tr> <tr><td>Date</td><td>".$_POST['date']."</td></tr> <tr><td>Event Type</td><td>".$_POST['EventType']."</td></tr> <tr><td>Food Type</td><td>".$_POST['FoodType']."</td></tr> <tr><td>Message</td><td>".$_POST['comments']."</td> </tr></table>" ; if ($sent = mail($to, $subject, $message, $headers)){ echo 'Thank you for your event request, we will be in touch soon.'; } }else{ foreach($errors as $error){ echo $error; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Event Form</title> </head> <body> <h1>Fill in the form and hit send to email us</h1> <form action="" method="post"> <input type="hidden" name="formsent" value="Sent" /> <table width="56%"> <tr> <td>Event Date:</td> <td width="25%"><input type="text" name="date" value="<?PHP echo $_POST['date']; ?>"/></td> <td width="25%"> </td> <td width="25%"> </td> </tr>
Code goes blank after submit and the nothing goes to my email.
Thank you for helping I appreciate all i can get.
Quote:
Originally Posted by sunfighter
Arcticwarrio code in post 6 works with one problem. It throws up errors for the check boxes. I fixed it in code below. But you need to make sure yhe form does not go blank, That the echo 'Thank you for your event request, we will be in touch soon.'; occurs in a better place (at the bottom and in color) ... Both should be done by stopping the html from exicuting the second time... And you have no checks in here to stop spamming.
So a good start on what you need is :
Code:
<?php
if (isset($_POST['email_address'])){
(isset($_POST["Birthday"]) ? $Birthday = "Birthday" : $Birthday = ""); /* NEXT 3 LINES ADDED */
(isset($_POST["Business"]) ? $Business = "Business" : $Business = "");
(isset($_POST["Wedding"]) ? $Wedding = "Wedding" : $Wedding = "");
// Load form field data into variables.
$email_address = $_POST['email_address'] ;
$comments = $_POST['comments'] ;
mail("yourname@example.com", "Event Form",
"Comments " . $comments . "<BR>
Date: " . $_POST["date"] . "<BR>
name: " . $_POST["name"] . "<BR>
Email: " . $email_address . "<BR>
<BR>
Event type: " . $Birthday."". $Business."". $Wedding . "<BR>" /* THIS HAS BEEN CHANGED */
, "From: $email_address" );
echo 'Thank you for your event request, we will be in touch soon.';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Event Form</title>
</head>
<body>
<h1>Fill in the form and hit send to email us</h1>
<form action="" method="post">
<table>
<tr>
<td>Event Date:</td>
<td><input type="text" name="date" value="" maxlength="100" /></td>
</tr>
<tr>
<td>Your Name:</td>
<td><input type="text" name="name" value="" maxlength="100" /></td>
</tr>
<tr>
<td>Email Address:</td>
<td><input type="text" name="email_address" value="" maxlength="100" /></td>
</tr>
<tr>
<td>Event type:</td>
<td>Birthday <input type="checkbox" name="Birthday" value"Birthday"/></td>
</tr>
<tr>
<td>Business <input type="checkbox" name="Business" value"Business"/></td>
<td>Wedding <input type="checkbox" name="Wedding" value"Wedding"/></td>
</tr>
<tr>
<td>Comments:</td>
<td><textarea rows="10" cols="50" name="comments"></textarea></td>
</tr>
<tr><td> </td>
<td>
<input type="submit" value="Send" />
</td>
</tr>
</table>
</form>
</body>
</html>
Putting the php in the head of the code is just to keep things confined. You should read all the posts here, a lot was said. You need to do some work on this code as I said. If it were me I'd put the php in it's own file, use ajax to contact to it, add a div to receive the 'Thank you for your event request, we will be in touch soon.' message, and definitely check for spammers and attacks.