Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-20-2013, 12:22 AM   PM User | #16
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.





.
mlseim is offline   Reply With Quote
Old 03-20-2013, 01:53 AM   PM User | #17
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 624
Thanks: 16
Thanked 70 Times in 70 Posts
Arcticwarrio is on a distinguished road
PHP Code:
<?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%">&nbsp;</td>
<td width="25%">&nbsp;</td>
</tr>

<tr>
<td>Your Name:</td>
<td width="25%"><input type="text" name="name" value="<?PHP echo $_POST['name']; ?>"/></td>
<td width="25%">&nbsp;</td>
<td width="25%">&nbsp;</td>
</tr>

<tr>
<td>Email Address:</td>
<td width="25%"><input type="text" name="email_address" value="<?PHP echo $_POST['email_address']; ?>"/></td>
<td width="25%">&nbsp;</td>
<td width="25%">&nbsp;</td>
</tr>

<tr>
<td>Event Type:</td>
<td width="25%">Birthday <input name="EventType" type="radio" value="Birthday" <?PHP if ($_POST['EventType'] == 'Birthday'){ echo 'checked="checked"';}?> /></td>
<td width="25%">Wedding
  <input type="radio" name="EventType" value="Wedding" <?PHP if ($_POST['EventType'] == 'Wedding'){ echo 'checked="checked"';}?> ></td>
<td width="25%">Business
  <input type="radio" name="EventType" value="Business" <?PHP if ($_POST['EventType'] == 'Business'){ echo 'checked="checked"';}?> ></td>
</tr>

<tr>
<td>Food Type:</td>
<td width="25%">Vegan <input type="radio" name="FoodType" value="Vegan" <?PHP if ($_POST['FoodType'] == 'Vegan'){ echo 'checked="checked"';}?>/></td>
<td width="25%">Traditional <input type="radio" name="FoodType" value="Traditional" <?PHP if ($_POST['FoodType'] == 'Traditional'){ echo 'checked="checked"';}?>></td>
<td width="25%">Gluten free <input type="radio" name="FoodType" value="Gluten_free" <?PHP if ($_POST['FoodType'] == 'Gluten_free'){ echo 'checked="checked"';}?>></td>
</tr>

<tr>
<td>Comments:</td>
<td colspan="3"><textarea rows="10" cols="50" name="comments"></textarea></td>
</tr>

<tr><td>&nbsp;</td>
<td width="25%">
<input type="submit" value="Send" /></td>
<td width="25%">&nbsp;</td>
<td width="25%">&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.

Last edited by Arcticwarrio; 03-20-2013 at 01:55 AM..
Arcticwarrio is offline   Reply With Quote
Old 03-22-2013, 10:45 PM   PM User | #18
Marifran
New Coder

 
Join Date: Mar 2013
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Marifran is an unknown quantity at this point
Sorry to say this code is not working either.

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 View Post
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>&nbsp;</td>
<td>
<input type="submit" value="Send" />
</td>
</tr>
</table>
</form>
</body>
</html>
Marifran is offline   Reply With Quote
Old 03-23-2013, 02:50 AM   PM User | #19
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 624
Thanks: 16
Thanked 70 Times in 70 Posts
Arcticwarrio is on a distinguished road
try post 17
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.
Arcticwarrio is offline   Reply With Quote
Old 03-23-2013, 04:03 PM   PM User | #20
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 361 Times in 360 Posts
sunfighter is on a distinguished road
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.
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Tags
check boxes, code, email, form, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:06 PM.


Advertisement
Log in to turn off these ads.