Page 1 of 1

Mail problem

Posted: Thu Jan 29, 2015 2:15 pm
by bigred73
I have designed a contact page everything seems to be work except that the email isn't getting through to the intend recipient. The sent mail logs show that the email was sent from the form, but the email is never received. I have used this same form for other websites, but for this one site I have having problems. Am I missing something or is the issue with the host site or some other problem? Here is the code I am using.

Code: Select all


<!DOCTYPE html PUBLIC "-//W3C//DTD Xhtml 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http=equiv="Content-Type" Content="text/html; charset=utf-8"/>
<title>Email Handle</title>
<style type="text/css" media="screen">
.error { color: red; }
</style>
</head>

<body>
<?php // Script 1.0 - email_handle.php

// Adjust for HTML tags:
$html_post = htmlentities($_POST['message']);
$strip_post = strip_tags($_POST['message']);

// Get the values from the $_POST array
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];

// Flag variable to track success:
$okay = TRUE;


// Validate the name:
if (empty($_POST['name'])) {
print '<p class="error">Please enter your name.</p>';
$okay = FALSE;
}

// Validate the email address:
if (empty($_POST['email'])) {
print '<p class="error">Please enter your email address.</p>';
$okay = FALSE;
}

// Validate the Phone:
if (empty($_POST['phone'])) {
print '<p class="error">Please enter your email address.</p>';
$okay = FALSE;
}

// Validate email address format:
if (empty($_POST['email']) || (substr_count($_POST['email'], '@') != 1) ) {
print '<p class="error">Please enter a valid email address.</p>';
$okay = FALSE;
}

if ($okay) {
print '<p>Thank you for your inquiry.</p>
<p>Someone will respond to your inquire as soon as possible.</p>';
}

// Make a link to another page:
$name = urlencode($name);
$email = urlencode($_POST['email']);
print "<p>Click <a href=\"index.html\">here</a> to return to the homepage.</p>";

// Send the mail
if ($_POST["email"]<>'') {
$ToEmail = 'email@somewhere.ca';
$EmailSubject = 'Site contact form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Phone: ".$_POST["phone"]."";
$MESSAGE_BODY .= "Message: ".nl2br($_POST["message"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
}
?>


I would appreciate any help. Thank you.

Re: Mail problem

Posted: Thu Jan 29, 2015 2:19 pm
by requinix
Checked the sendmail logs on your server? Have you tried sending to different email addresses to see if it's a problem with a particular service?

Re: Mail problem

Posted: Thu Jan 29, 2015 2:22 pm
by Celauran
If it's sent and not received, I'd surmise it's being marked as spam. Do you have SPF enabled?

Re: Mail problem

Posted: Thu Jan 29, 2015 2:28 pm
by bigred73
One addition information.

In the sendmail log it has four headers: Email Subject, Script, Request IP and Date.
The log has Email subjects and dates of emails sent, but nothing in the Script and request IP.

Re: Mail problem

Posted: Thu Jan 29, 2015 2:31 pm
by bigred73
SPF are off.

Re: Mail problem

Posted: Thu Jan 29, 2015 2:38 pm
by bigred73
requinix, I will try that. thanks.

Re: Mail problem

Posted: Thu Jan 29, 2015 2:46 pm
by Celauran
bigred73 wrote:SPF are off.
That's definitely working against you.

Re: Mail problem

Posted: Thu Jan 29, 2015 3:10 pm
by bigred73
I tried a couple of email address and the same problem. I wonder if it is the webhost. I am using 1freehosting. Anythoughts on this hosting site? The reason I am wondering if it is the hostsite is because I have used the same script for a few other sites and have no problems. It is only for this one website.

Celauran, would it be on the receiving or sending side of the email that I need to have SPF on?

Re: Mail problem

Posted: Thu Jan 29, 2015 3:15 pm
by Celauran
You'd need to enable it at the hosting level. Take a look at this article and this utility. Your hosting provider should be able to help if you're having difficulty getting this set up for your domain.

Re: Mail problem

Posted: Thu Jan 29, 2015 3:29 pm
by bigred73
Thanks Celauran. I'll look into that.

Re: Mail problem

Posted: Sun Jul 10, 2016 3:52 pm
by TopCoder
@bigred73

I know this is an old post, but if you're still using that contact form, you're going to have issues with the new DMARC standards, they been enabled at GMAIL and YAHOO.

You'll need to change

Code: Select all

$mailheader = "From: ".$_POST["email"]."\r\n";
to

Code: Select all

$mailheader = "From: email@somewhere.ca\r\n";
Without doing that, anyone who uses your contact us form, from GMAIL or YAHOO you will not receive.