0

I'm trying to set up a contact me page and currently I've got it working all the way to the point of the 'message sent' result showing up correctly. However the e-mail never shows up for me in my box inbox.

<?php

    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    $antispam = $_POST['antispam'];
    $to = 'myemailaddress@gmail.com';
    $from = 'From : ' . $email;

    $body = "From: $name\n E-Mail: $email\n Message:\n $message";

    if ($antispam == '10' || 'Ten' || 'ten') {
        $human = true;
    }

    if($_POST['submit'] &&  $name != "" && $email != "" && $message != "" && $subject != "") {
        if ($human == true) {
            if (mail($to, $subject, $body, $from)) {
                $result = "Your message was sent successfully!";
            } else {
                $result = "Something went wrong! Try sending your message again";
            }
        } else {
            $result = "You answered the anti-spam answer incorrectly. Please try again.";
        }
    } else {
        $result = "You did not fill out a required field. Please try again.";
    }

?>

<?php echo $result; ?>

I've read seperately that Gmail has issues with PHP mail(), is that possibly the cause?

FirstOrderKylo
  • 99
  • 3
  • 12
  • 3
    `if (antispam` right there, is an undefined constant error and that conditional's failing for another reason, being invalid. We also don't know what the form looks like. – Funk Forty Niner Aug 28 '16 at 23:34
  • @Fred-ii- I dont quite understand. When i enter the correct value on the first screen and submit I get `$result = "Your message was sent successfully!";` which tells me its working? But i still never recieve my email – FirstOrderKylo Aug 28 '16 at 23:36
  • 2
    See for yourself. http://php.net/manual/en/function.error-reporting.php set to catch and display and you'll see what I mean. This whole bit `if (antispam == '10' || 'Ten' || 'ten') { $human = true; }` isn't working at all here; 2 major errors in there. check your spam also. – Funk Forty Niner Aug 28 '16 at 23:37
  • can u try it like this " . "\r\n"); ?> and see if that work or not – Mouner Mostafa Aug 28 '16 at 23:40
  • @Fred-ii- alright I found one issue and feel dumb for not seeing it. `if(antispam` was supposed to be `if($antispam` so I changed that but I still don't receive the email (i checked the spam folder too) – FirstOrderKylo Aug 28 '16 at 23:45
  • 1
    try using a basic mailing example without all the conditionals. If and when things start to work, put your conditionals back in one by one and retest. Once it starts to fail, you'll know what to go after. – Funk Forty Niner Aug 28 '16 at 23:57
  • @Fred-ii- I found the answer and posted it below. To be short I never told it to actually send the email, just check if it was possible then set the result variable. – FirstOrderKylo Aug 29 '16 at 00:14

1 Answers1

1

I found the answer and honestly feel dumber for not recognizing it.

It was never told to send the email, just check if sending it would be true or not. I know that sounds weird but here's the old code:

         if ($human == true) {
            if (mail($to, $subject, $body, $from)) {
                $result = "Your message was sent successfully!";
            } else {
                $result = "Something went wrong! Try sending your message again";
            }

and here's the fixed version

         if ($human == true) {
            mail($to, $subject, $body, $from);
            if (mail($to, $subject, $body, $from)) {
                $result = "Your message was sent successfully!";
            } else {
                $result = "Something went wrong! Try sending your message again";
            }

to be short, I added mail($to, $subject, $body, $from); after the check to see if $human == true

FirstOrderKylo
  • 99
  • 3
  • 12