Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    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.





    .

  2. #17
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    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>
    Last edited by Arcticwarrio; 03-20-2013 at 02:55 AM.
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  3. #18
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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>

  4. #19
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    try post 17
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  5. #20
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,722
    Thanks
    25
    Thanked 662 Times in 661 Posts
    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.


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •