Reputation: 33
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 = '[email protected]'; it works perfectly. But if i use my email address associated to the website i mean like $mail_to = '[email protected]'; 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 = '[email protected]';
$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 [email protected]');
window.location = 'index.html';
</script>
<?php
}
?>
Upvotes: 3
Views: 58
Reputation: 52
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 :)
Upvotes: 1