Form Sending From Entered Email Address Not Mine?

Hey guys,
I have no clue why this is happening. When someone would fill out the Name, Email, and Confirm Email it sends the second email to the user from their own email address not mine. Can someone please help me here?

"Thank you for entering to win 200 dollars. Please check this email address later to see if your the lucky winner!

Sincerely,"

Should say it was sent from [email protected]

Thanks for any help!

HTML:
[php]

ENTER TO WIN $200


Full Name:
Email Address:
Confrim Email:

[/php]

PHP:
[php]

<?php // first clean up the input values foreach($_POST as $key => $value) { if(ini_get('magic_quotes_gpc')) $_POST[$key] = stripslashes($_POST[$key]); $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key])); } $ip=$_SERVER['REMOTE_ADDR']; $email_to = "[email protected]"; $email_subject = "200 Entry | "; $email_message .= "Name Entered: ".$_POST["fname"]."\n"; $email_message .= "Email Address: ".$_POST["lname"]."\n"; $email_message .= "Confirm Email: ".$_POST["email"]."\n"; $userEmail = filter_var( $_POST['email'],FILTER_VALIDATE_EMAIL ); if( ! $userEmail ){ exit; } //email headers $headers = 'From: '.$_POST["email"]."\r\n". 'Reply-To: '.$_POST["email"]."\r\n" . 'X-Mailer: PHP/' . phpversion(); echo (mail($email_to, $email_subject, $email_message, $headers) ? " ":"

We're sorry, something went wrong.

Please return to .

"); $ip=$_SERVER['REMOTE_ADDR']; $email_to = $_POST["email"]; $email_subject = "Giveaways | "; $email_message1 = "Welcome to ! Thank you for entering to win 200 dollars. Please check this email address later to see if your the lucky winner! Sincerely, "; //email headers $headers = 'From: '.$_POST["email"]."\r\n". 'Reply-To: '.$_POST["email"]."\r\n" . 'X-Mailer: PHP/' . phpversion(); echo (mail($email_to, $email_subject, $email_message1, $headers) ? "":""); exit(); // test input values for errors $errors = array(); if(strlen($fname) < 2) { if(!$fname) { $errors[] = "You must enter a name."; } else { $errors[] = "Name must be at least 2 characters."; } } if(!$email) { $errors[] = "You must enter an email."; } else if (!validEmail($email)) { $errors[] = "You must enter a valid email."; } if($errors) { // output errors to browser and die with a failure message $errortext = ""; foreach($errors as $error) { $errortext .= "
  • ".$error."
  • "; } die("The following errors occured:
      ". $errortext ."
    "); } // check to see if email is valid function validEmail($email) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { $isValid = false; } else { $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64) { $isValid = false; } // local part length exceeded else if ($domainLen < 1 || $domainLen > 255) { $isValid = false; } // domain part length exceeded else if ($local[0] == '.' || $local[$localLen-1] == '.') { $isValid = false; } // local part starts or ends with '.' else if (preg_match('/\\.\\./', $local)) { $isValid = false; } // local part has two consecutive dots else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { $isValid = false; } // character not valid in domain part else if (preg_match('/\\.\\./', $domain)) { $isValid = false; } // domain part has two consecutive dots else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { // character not valid in local part unless local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; } } if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { $isValid = false; } // domain not found in DNS } return $isValid; } ?>

    [/php]

    Your code is very messy, but, you do have two email functions in your code, and therefore two emails
    should be sent out.

    You have:
    echo (mail($email_to, $email_subject, $email_message1, $headers) ? “”:"");

    This does not really make sense to me. You send an email and then do some optional compare?
    Normally emails are sent like this:
    $email_sent = mail($email_to, $email_subject, $email_message1, $headers);
    if ($email_sent) {
    handle your email was sent message…
    } else {
    handle your errors… (email was not sent out)…
    }
    Often the handling of errors are done way before actually sending out the email to make sure that the
    errors were not sent in the email.

    Well, your code is designed to send out two emails, so it should do that…

    I got that code from trial and error off a contact form from before. All the error codes do nothing at the bottom of the page. The code should simply send me the fields and send the user that message. The code works as it is but sends the message from the email entered in the field >:( I cant figure out what to change to make it send from [email protected] when they receive the message.

    I tired cleaning up the code and using what you said the only problem now is the issue is still there and the now wont send me the fields

    [php]<?php

    // first clean up the input values
    foreach($_POST as $key => $value) {
    if(ini_get(‘magic_quotes_gpc’))
    $_POST[$key] = stripslashes($_POST[$key]);

    $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
    }

    $ip=$_SERVER[‘REMOTE_ADDR’];
    $email_to = “[email protected]”;
    $email_subject = "200 Entry | ";

    $email_message .= “Name Entered: “.$_POST[“fname”].”\n”;
    $email_message .= “Email Address: “.$_POST[“lname”].”\n”;
    $email_message .= “Confirm Email: “.$_POST[“email”].”\n”;

    //email headers

    $headers = 'From: '.$_POST[“email”]."\r\n".

    'Reply-To: '.$_POST[“email”]."\r\n" .

    ‘X-Mailer: PHP/’ . phpversion();

    echo (mail($email_to, $email_subject, $email_message, $headers) ? "
    ":“

    We’re sorry, something went wrong.

    Please return to .

    ”);

    $ip=$_SERVER[‘REMOTE_ADDR’];
    $email_to = $_POST[“email”];
    $email_subject = “Giveaways | 3 TOP 3”;

    $email_message1 = "Welcome to 3 TOP 3!

    Thank you for entering to win 200 dollars. Please check this email address later to see if your the lucky winner!

    Sincerely,

    ";

    //email headers

    $headers = 'From: '.$_POST[“email”]."\r\n".

    'Reply-To: '.$_POST[“email”]."\r\n" .

    ‘X-Mailer: PHP/’ . phpversion();

    $email_sent = mail($email_to, $email_subject, $email_message1, $headers);
    if ($email_sent)

    exit();

    ?>

    [/php]

    Your mail-to is set at $email_to = “[email protected]”;

    Just change it to where you want the email to really go. Like [email protected]

    Thanks for the response but I purposely changed the web addresses so search engines don’t pick up the name.

    After a few tests the code seems to be back to the original problem, both emails send but the one the user receives still comes back as from their email address.

    You are sending mail twice, which it appears is what you want. But, both use this,

    $headers = 'Reply-to: '.$_POST[“email”]."\r\n".

    Which, means both emails will have the same reply to addresses.

    HUH? Search engines normally do NOT see your PHP code. That is hidden on the server. All PHP is not
    shown on the finished pages. Also, you can just use a ROBOTS.txt file to stop them from searching your
    site if you wish. Or even, just not allow them to search your one page that has you email address in it.

    Have you ever VIEWED-SOURCE of your page once it is in the browser. You will NEVER see any PHP code
    in it unless you put it there as some sort of text display. That is why PHP is safer than JS and JQuery.

    As far as your code goes, I had a lot of trouble sending emails with my shared hosting service on one site.
    It was Godaddy.com. For that one email system, I had to make sure I used their address for the sending
    of the email. Otherwise, they dropped them due to spam rules. Are you hosted with them? Some of the
    hosting services out there need SMTP for sending emails. Sometimes you have to email thru special ways.
    Have you been able to just do very simple emails from the server? I would start by just creating a very
    simple script to send out a test email. If it goes thru, then find out what is different in your full code.

    I didn’t know about that with the PHP code thank you for that info! Ill show you the full code. I don’t think its my hosting because with the same code Ive had to work just different domain name.

    [php]<?php

    // first clean up the input values
    foreach($_POST as $key => $value) {
    if(ini_get(‘magic_quotes_gpc’))
    $_POST[$key] = stripslashes($_POST[$key]);

    $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
    }

    $ip=$_SERVER[‘REMOTE_ADDR’];
    $email_to = “info@********.com”;
    $email_subject = “200 Entry | 3 TOP 3”;

    $email_message .= “Name Entered: “.$_POST[“fname”].”\n”;
    $email_message .= “Email Address: “.$_POST[“lname”].”\n”;
    $email_message .= “Confirm Email: “.$_POST[“email”].”\n”;

    //email headers

    $headers = 'From: '.$_POST[“email”]."\r\n".

    'Reply-To: '.$_POST[“email”]."\r\n" .

    ‘X-Mailer: PHP/’ . phpversion();

    echo (mail($email_to, $email_subject, $email_message, $headers) ? "
    ":“

    We’re sorry, something went wrong.

    Please return to 3 TOP 3.

    ”);

    $ip=$_SERVER[‘REMOTE_ADDR’];
    $email_to = $_POST[“email”];
    $email_subject = “Giveaways | 3 TOP 3”;

    $email_message1 = "Welcome to 3 TOP 3!

    Thank you for entering to win 200 dollars. Please check this email address later to see if your the lucky winner!

    Sincerely,
    3 TOP 3
    ";

    //email headers

    $headers = 'From: '.$_POST[“email”]."\r\n".

    'Reply-To: '.$_POST[“email”]."\r\n" .

    ‘X-Mailer: PHP/’ . phpversion();

    $email_sent = mail($email_to, $email_subject, $email_message1, $headers);
    if ($email_sent)

    exit();

    ?>

    [/php]

    Perhaps I wasn’t clear. You should not post your email addresses on blogs, but, in your own PHP code, it is
    safe on your server. I will remove yours here…

    Now, as far as the code goes, again, Astonecipher and I have told you that your FROM and REPLY-TO is set
    inside your code. Therefore, they are sent as you set them up to be. If you want the REPLY-TO to be set to
    your address, you have to alter the code to say so. Just change the HEADERS set up to alter them to what
    you wish them to be.

    I’m sorry for all the confusion, but thank all of you for the help!
    I have changed the $headers = 'From: '.$_POST[“email”]."\r\n".
    to $headers = 'From: '.$_POST[“[email protected]”]."\r\n".
    this time none are sent at all :-X

    LOL, close…

    Try:

    $headers = ‘From: [email protected]’ . “\r\n”.

    … nevermind …

    Sponsor our Newsletter | Privacy Policy | Terms of Service