Mail problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bigred73
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2015 1:54 pm

Mail problem

Post 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.
Last edited by requinix on Thu Jan 29, 2015 2:16 pm, edited 1 time in total.
Reason: fixed syntax tags
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Mail problem

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Mail problem

Post by Celauran »

If it's sent and not received, I'd surmise it's being marked as spam. Do you have SPF enabled?
bigred73
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2015 1:54 pm

Re: Mail problem

Post 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.
Attachments
sendmail log pic
sendmail log pic
bigred73
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2015 1:54 pm

Re: Mail problem

Post by bigred73 »

SPF are off.
bigred73
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2015 1:54 pm

Re: Mail problem

Post by bigred73 »

requinix, I will try that. thanks.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Mail problem

Post by Celauran »

bigred73 wrote:SPF are off.
That's definitely working against you.
bigred73
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2015 1:54 pm

Re: Mail problem

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Mail problem

Post 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.
bigred73
Forum Newbie
Posts: 6
Joined: Thu Jan 29, 2015 1:54 pm

Re: Mail problem

Post by bigred73 »

Thanks Celauran. I'll look into that.
TopCoder
Forum Newbie
Posts: 8
Joined: Sun Jul 10, 2016 3:38 pm

Re: Mail problem

Post 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.
Post Reply