0

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 {}  ?>
Community
  • 1
  • 1
  • probably when the form submitter puts something invalid in as an email address –  Sep 06 '16 at 21:06

1 Answers1

0

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.

Community
  • 1
  • 1
Kaylined
  • 655
  • 6
  • 15
  • standard approach on most mail forms, makes replying easy –  Sep 06 '16 at 21:16
  • @Kaylined Thanks, but for the last header, Reply-to, shouldn't it be $email? The way you have it, I was replying to my own email address. So I have this: $from = 'info@mysite.com'; $headers .= "From: $from\r\n"; $headers .= "Reply-To: $email \r\n"; –  Sep 07 '16 at 15:26
  • that would work yes. Only problem is with mismatching information like that, if you're sending to services like gmail you're going to get spam-foldered. Is it really that difficult to "copy-paste" the email address out of the body? – Kaylined Sep 07 '16 at 15:38