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.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Email form(email not required fix)

    Hey all-
    I have the following php for a form email:
    <?php
    $to = "myemail@gmail.com.com" ;
    $from = $_REQUEST['Email'] ;
    $name = $_REQUEST['Name'] ;
    $headers = "From: $from";
    $subject = "RSVP";

    $fields = array();
    $fields{"Name"} = "Name";
    $fields{"Email"} = "Email";
    $fields{"RSVP"} = "RSVP";
    $fields{"Message"} = "Message";

    $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

    $headers2 = "From: myemail@gmail.com";
    $subject2 = "Thank you for RSVP'ing";
    $autoreply = "Thank you for RSVP'ing! We hope that you checked that you were coming. We can't wait for July 24th! Kristi & Graham";

    if($from == '') {print "You have not entered an email, please go back and try again";}
    else {
    if($name == '') {print "You have not entered a name, please go back and try again";}
    else {
    $send = mail($to, $subject, $body, $headers);
    $send2 = mail($from, $subject2, $autoreply, $headers2);
    if($send)
    {header( "Location: http://www.mysite.com/index.html" );}
    else
    {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
    }
    }
    ?>


    It works fine as is. (it's an RSVP for my wedding). I don't want an email to be necessary though. When I take out:
    if($from == '') {print "You have not entered an email, please go back and try again";} , hitting submit on my html page just takes the browser to a blank page that is .../contact.php.

    How can i fix this so email isn't required, and the page is redirected towards my index?

    Thanks in advance.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,540
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    The "blank page" is because you have a PHP script error, and your PHP error reporting is turned-off with your webhost account.

    So, I'm guessing when you remove that line you mentioned, the "else" statement needs to go too.

    You might want to turn-on error reporting to get an idea of what the error is, and what line:
    http://php.net/manual/en/function.error-reporting.php

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    25
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Try that...also I suggest using $_GET or $_POST instead of $_REQUEST...and echo instead of print. Ask any questions,
    Sam

    PHP Code:
    <?php 
    $to 
    "myemail@gmail.com.com" 
    if(
    $_REQUEST['Email'] == '') {
    $from 'noemail@rsvp.com';
    } else {
    $from $_REQUEST['Email'] ; 
    }
    if(
    $_REQUEST['Name'] == '') {
    die(
    "You have not entered a name, please go back and try again");
    } else {
    $name $_REQUEST['Name'] ;

    $headers "From: $from"
    $subject "RSVP"

    $fields = array(); 
    $fields{"Name"} = "Name"
    $fields{"Email"} = "Email"
    $fields{"RSVP"} = "RSVP"
    $fields{"Message"} = "Message"

    $body "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

    $headers2 "From: myemail@gmail.com"
    $subject2 "Thank you for RSVP'ing"
    $autoreply "Thank you for RSVP'ing! We hope that you checked that you were coming. We can't wait for July 24th! Kristi & Graham";

    $send mail($to$subject$body$headers); 
    $send2 mail($from$subject2$autoreply$headers2); 
    if(
    $send
    {
    header"Location: http://www.mysite.com/index.html" );} 
    else 
    {print 
    "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } 
    }
    }
    ?>

  • #4
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    The "blank page" is because you have a PHP script error, and your PHP error reporting is turned-off with your webhost account.

    So, I'm guessing when you remove that line you mentioned, the "else" statement needs to go too.

    You might want to turn-on error reporting to get an idea of what the error is, and what line:
    http://php.net/manual/en/function.error-reporting.php
    Thanks for the responses....
    I can't seem to figure out how to turn on error reporting in the code in my initial post. Any help? Thanks!

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Just after the opening php tag at the top of the script, add:

    Code:
    error_reporting(E_ALL);


  •  

    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
    •