简体   繁体   中英

My server's name shows up as submitter's Reply-to email address from PHP contact Form

I'm not versed in PHP and had this form built for me. It works 95% of the time, but sometimes the reply-to email will be johnsmith@hadrian.lunarpages.com

I'm reading up a similar issue on this page , but not exactly sure what to change in my form...

<?php
if (isset($_REQUEST['btnSubmit-group'])) {
    $date = $_REQUEST['date'];
    $time = $_REQUEST['time'];
    $count = $_REQUEST['count'];
    $name = $_REQUEST['name'];
    $organization = $_REQUEST['organization'];
    $email = $_REQUEST['email'];
    $grouptype = $_REQUEST['grouptype'];   
    $phone = $_REQUEST['phone'];
    $upgrademus = $_REQUEST['upgrademus'];
    $upgradeowo = $_REQUEST['upgradeowo'];
    $comments = $_REQUEST['comments'];
    $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

    if ($count == "" || $name == "" || $email == "" || $phone == "") {
        echo "All fields are required, please fill out again. ";
    } else {
        $to = 'info@example.com';
        $subject = "Group Tour Inquiry from $name ($date, $count people)";
        $from = $to;
        $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

        $body = nl2br("Private Tour:<br>" .
                "<b>Name:</b>   $name\r\n" .
                "<b>Email:</b>  $email \r\n" .
                "<b>Phone:</b>  $phone \r\n" .
                "<b>Organization:</b>     $organization\r\n" .
                "<b>Date:</b>     $date\r\n" .
                "<b>Time:</b>     $Time\r\n" .
                "<b>Count:</b>     $count\r\n" .
                "<b>Include:</b>     $upgrademus\r\n" . 
                "<b>Include:</b>     $upgradeowo\r\n" .
                "<b>Comments:</b>     $comments\r\n" .
                "");
// To send HTML mail, the Content-type header must be set
        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= "From: $name<$email> \r\n";
        $headers .= "Reply-To: $email \r\n";

        if (mail($to, $subject, $body, $headers)) {
            echo "<div class=\"thankyou\"></div><meta http-equiv='refresh' content='0;url=http://www.example.com/private-group-tours'>";
        }
    }
} else {}  ?>

You're trying to send e-mail's to your self FROM the person whose entering this in, essentially attempting to spoof their email, and sometimes this will(should) get blocked. more can be read here - problem with php mail 'From' header

Change:

    $headers .= "From: $name<$email> \r\n";
    $headers .= "Reply-To: $email \r\n";

to

    $from = 'Admin@mysite.com';

    $headers .= "From: $from\r\n";
    $headers .= "Reply-To: $from \r\n";

and then edit that static $from variable. Then take the users email out of the BODY of the email you receive, and send them an email.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM