Results 1 to 3 of 3

Thread: [RESOLVED] Problem Emailing Form Data

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    Resolved [RESOLVED] Problem Emailing Form Data

    Hello,

    I am trying to do a simple form data PHP page. Basically, I need to collect a users name and email address, then have that data emailed to me once they click a "send" button. I found some free code online at http://formtoemail.com/ and copy/pasted their code as instructed.
    The form loads up and looks find, and I entered all the fields and clicked "send"
    I noticed a very strange behavior....the form will only send me the data at my email if the email I enter on the form is the same email as the email I am using as my email on the PHP page that codes all the functions for getting and sending the mail. I tried sending email from another (valid) email address to the one on the PHP page, and get nothing. So right now the PHP code doesn't work for me. Here is the code for both the form, and the PHP page.
    Please let me know if you see any reason for this behavior, and how to correct it so that I can receive email addresses and comments from other users, not just myself. Thanks.

    (if you would like to see the original code, it can be found at http://formtoemail.com/FormToEmail.txt)





    Form Code
    Code:
    <form action="FormToEmail.php" method="post">
    <table border="0" bgcolor="#ececec" cellspacing="5">
    <tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
    <tr><td>Email address</td><td><input type="text" size="30" name="email"></td></tr>
    <tr><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr>
    <tr><td>&nbsp;</td><td><input type="submit" value="Send"><font face="arial" size="1">&nbsp;&nbsp;<a href="http://FormToEmail.com">Form Mail</a> by FormToEmail.com</font></td></tr>
    </table>
    </form>
    PHP Code:

    Code:
    $errors = array();
    
    // Remove $_COOKIE elements from $_REQUEST.
    
    if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
    
    // Validate email field.
    
    if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
    {
    
    $_REQUEST['email'] = trim($_REQUEST['email']);
    
    if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}
    
    }
    
    // Check referrer is from same site.
    
    if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}
    
    // Check for a blank form.
    
    function recursive_array_check_blank($element_value)
    {
    
    global $set;
    
    if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
    else
    {
    
    foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}
    
    }
    
    }
    
    recursive_array_check_blank($_REQUEST);
    
    if(!$set){$errors[] = "You cannot send a blank form";}
    
    unset($set);
    
    // Display any errors and exit if errors exist.
    
    if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
    
    if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}
    
    // Build message.
    
    function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
    
    $message = build_message($_REQUEST);
    
    $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com";
    
    $message = stripslashes($message);
    
    $subject = "FormToEmail Comments";
    
    $subject = stripslashes($subject);
    
    $from_name = "";
    
    if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}
    
    $headers = "From: {$from_name} <{$_REQUEST['email']}>";
    
    mail($my_email,$subject,$message,$headers);
    
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    
    <head>
    <title>Form To Email PHP script from FormToEmail.com</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body bgcolor="#ffffff" text="#000000">
    
    <div>
    <center>
    <b>Thank you <?php if(isset($_REQUEST['name'])){print stripslashes($_REQUEST['name']);} ?></b>
    <br>Your message has been sent
    <p><a href="<?php print $continue; ?>">Click here to continue</a></p>
    <p><b>FormToEmail</b> by <a href="http://FormToEmail.com">FormToEmail.com</a></p>
    </center>
    </div>
    
    </body>
    </html>

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    Re: Problem Emailing Form Data

    Maybe that last post wasn't entirely clear. I just re-read it. Here's an example of what is happening.

    I put in [email protected] as my email address in the code. This is where all users emails should be forwarded to.

    However, nothing gets sent to [email protected] when I (or others) try putting in another email address in the form, such as [email protected], or some other valid email address.

    Now, when I put in [email protected] on the form, the email will be forwarded to me, at [email protected]. This is the only email address that will cause an email to be generated to me. Unfortunately, [email protected] is my email address, so it is useless to me.

    Can anyone think of a reason why the form would only send an email to me if I put in my own email address in the form? Thanks!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    Re: Problem Emailing Form Data

    The issue has been resolved. Thanks.
    Last edited by starscrea2; Aug 7th, 2008 at 07:56 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width