Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29957

PHP email sent successfully but not received by Gmail

$
0
0

I have some code that has worked for me in the past, but isn't anymore, for some reason I don't understand. I'm pretty sure the problem isn't in the code itself, since 1) I haven't changed anything, and 2) it's worked for me in the past. I am using XAMPP and PHP.

My webpage allows a user to fill out a contact form and send an email through PHP. It seems to execute successfully, since it takes the user to "thankyou.html" as a result. To troubleshoot the issue, I have 1) cleared my browser's cache and 2) checked my spam folder in Gmail.

But I still can't find my email, and don't know why. I'm not familiar with how SMTP works; if the problem has to do with that, then I would appreciate an explanation.

Here is the code:

<?php
$field_first_name = $_POST['cf_first_name'];
$field_last_name = $_POST['cf_last_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$field_reference = $_POST['cf_reference'];

$mail_to = 'myself@gmail.com';
$subject = 'Message from a website visitor '.$field_first_name.''.$field_last_name;

$body_message = 'From: '.$field_first_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message."\n";
$body_message .= 'Reference: '.$field_reference;

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

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
        <script language="javascript" type="text/javascript">
                //alert('Thank you for the message. We will contact you shortly.');
                window.location = 'thankyou.html';
        </script>
<?php
}
else { ?>
        <script language="javascript" type="text/javascript">
                alert('Message failed. Please, send an email to someemail@gmail.com');
                window.location = 'home.php';
        </script>
<?php
}
?>

Any input is much appreciated!


Viewing all articles
Browse latest Browse all 29957

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>