简体   繁体   中英

contact_us.php isn't sending emails to my website associated mail address

I'm using this contact_us.php file to enable 'Contact us' section of my website. If i use my gmail or hotmail address here for $mail_to = 'user@gmail.com'; it works perfectly. But if i use my email address associated to the website i mean like $mail_to = 'user@mywebsite.com'; i'm not getting any mail to my inbox. I even checked my spam and all other folder. Can anyone please help me with this? How can i get emails to the email address associated with my website. Thanks in advance.

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'user@mywebsite.com';
$subject = 'Message from a site visitor '.$field_name;

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

$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 = 'index.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to user@yahoo.com');
        window.location = 'index.html';
    </script>
<?php
}
?>

If you do not want to use mail function, than try SMTP mail from PHPmailer library.

You will be able to send email from your gmail or outlook or any other smtp account from your website. sharing you the link below:

https://github.com/PHPMailer/PHPMailer/tree/master/examples

Enjoy :)

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