• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

Email issue - Sends to some addresses and not others.

I am doing a website which will have a pretty typical Contact Us page. It contains an email form
where the sender enters his name, email address and message. The form then reloads the page and a php routine which does some cursory checks, sets up the email and then sends it, using the PHP mail() function.

When testing it, the form successfully sent to two different email addresses, but when I set the
receiving address to the address my client wants, the message never arrives. I do not have any sort of routine to receive delivery error messages, so I cannot tell why it fails. The mail
function consistently indicates the mail was successfully sent.

I have successfully sent to this address using my personal email client (Outlook 2007) so I know the address is valid.

I have included the PHP code and HTML form code in the attached file.

How do I fix this? email-code.txt
0
gpinzino
Asked:
gpinzino
  • 13
  • 9
  • 5
  • +3
3 Solutions
 
MISOperationsCommented:
Add the address that it is coming from to the exception list in their email, it could be getting blocked.
0
 
Dave BaldwinFixer of ProblemsCommented:
If it is sending to two email addresses ok, then the problem isn't with the PHP.  You may need to use a verifiable 'From' address.  Some mail filtering software checks to see if the 'From' address is valid.  Unroutable or private IPs are also sometimes blocked because so many have been used to send spam.  Try sending it from his email address to his email address.
0
 
gpinzinoAuthor Commented:
Thank you both for your immediate responses. I don't know that I can add it to the white list, since the user inserts their email address when sending a message. The email address of the sender will be different every time.

Dave, I will try making the reipient email address the sender address as well and see if it helps.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
billmercerCommented:
DaveBaldwin's right, if the messages are going out to some addresses, it's very unlikely to be a problem with the sender.

What I usually do when troubleshooting things like this is do an mx lookup on the problem address, then try telnetting into the server and manually typing SMTP commands to see what happens.
Here's a reference...  
  http://arnab.org/notes/using-telnet-to-send-mail-by-smtp
0
 
gpinzinoAuthor Commented:
Bill,
Thanks for your input. If Dave's fix doesn't do it, I will try telnet option.
0
 
Ray PaseurCommented:
I would use a predictable (ie: the same every time) From address, and simply include the email address from the form in the body of the email.  That way your client can white-list one email address -- the From address, and can always know that messages from, for example, iRobot@yourdomain.com contain the form data.  Maybe something like the code snippet.  Put your own custom information in around lines 15-22 and try it out.
<?php // RAY_form_to_email.php
error_reporting(E_ALL);

// SEND MAIL FROM A FORM

// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    $str = stripslashes($str);
    $str = trim(preg_replace("/ +/", " ", $str));
    $str = preg_replace('/^ a-zA-Z0-9&+:?_\.\-/', '', $str);
    return $str;
}

// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR WORK
$from  = "NoReply@Your.org";
$subj  = "Contact Form";

// THIS IS AN ARRAY OF RECIPIENTS
$to[]  = "You@Your.org";
$to[]  = "Her@Your.org";
$to[]  = "Him@Your.org";

// IF THE DATA HAS BEEN POSTED
if (!empty($_POST['email']))
{
    // CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
    $email      = clean_string($_POST["email"]);
    $name       = clean_string($_POST["name"]);
    $telephone  = clean_string($_POST["telephone"]);

    // CONSTRUCT THE MESSAGE
    $content    = '';
    $content   .= "You have a New Query From $name" . PHP_EOL . PHP_EOL;
    $content   .= "Tel No: $telephone" . PHP_EOL;
    $content   .= "Email: $email" . PHP_EOL;

    // SEND MAIL TO EACH RECIPIENT
    foreach ($to as $recipient)
    {
        if (!mail( $recipient, $subj, $content, "From: $from\r\n"))
        {
            echo "MAIL FAILED FOR $recipient";
        }
        else
        {
            echo "MAIL WORKED FOR $recipient";
        }
    }
} // END OF PHP - PUT UP THE FORM
?>
<form method="post">
<br/>Email: <input name="email" />
<br/>Phone: <input name="telephone" />
<br/>Name:  <input name="name" />
<br/><input type="submit" />
</form>

Open in new window

0
 
Vimal DMSenior Software EngineerCommented:
Hai,

"PHPMAILER" is the best one to process the mailing events

1) Can send bulk mails
2) Can have bulk attachment
3) Can avoid spams
4) Any type of mail id's will be accepted to the mailer class
0
 
gpinzinoAuthor Commented:
Ray Passeur,
vimalmaria,

Thank you both for your insightful comments. It will be very difficult to decide which suggestions to accept as solutions.

You guys are great!
0
 
Ray PaseurCommented:
I think DaveBaldwin's comment at http:#35032033 is right on, too.
0
 
gpinzinoAuthor Commented:
Status update.

I am still trying to fix this problem with the email form. I have tried and failed with:
* Setting the sender and recipient to the same address.
* White listing the sender's email address.
* Sending the email to a different box on the same domain.

I am considering PHPMailer, but I am having trouble with the download, and I am not sure I would be able to correctly configure it. The SMTP solution, likewise would probably give me the greatest control over the process, but I feel I would be reinventing the email wheel and I am not simply not up to that task. Of all the skills web developers need, email is probably my weakest.
0
 
Dave BaldwinFixer of ProblemsCommented:
You should use your own email address as the 'From:' address for a test to see if you even get a bounce or NDR message.  If you do, you can see what the error is.  If you don't, then whatever spam filters they have are simply dropping your emails.  That is not uncommon.
0
 
Ray PaseurCommented:
Have you tried the script I posted at http:#35032361 ?  If not, give it a go, and put my public email address as one of the "to" addresses.  Please use Ray.Paseur@Gmail.com so I can see what is getting injected into your mail headers.
0
 
gpinzinoAuthor Commented:
Dave, I will give yours a try and see if I get anything.
Ray, likewise, I'll send you a message through the site. Let me know what you see.
0
 
Ray PaseurCommented:
Have you sent it yet?  I have seen nothing, even in spam.
0
 
gpinzinoAuthor Commented:
Yes, it went out a few minutes ago.
0
 
Ray PaseurCommented:
The email came through and did not go to Gmail spam.  The SPF looks good.  A couple of things that might be tripping this up...

The return path and the from address are on different servers.  The X-PHP-Script and X-Antiabuse headers may trigger some spam filters.

A check of this site turned up nothing to be concerned about.
http://www.mxtoolbox.com/SuperTool.aspx?action=blacklist%3a174.120.252.82

The problem with email spam filters is that they are completely unreliable.  Because there is no standard for email, there are as many kinds of "validation" as there are people who think they can outsmart the spammers.  I expect you are running into that kind of situation.  So my advice is to use the same FROM address and REPLY TO address in all the messages you send, and on the form that picks up the client information, put a prominent note asking the client to white-list that address.

HTH, ~Ray
Delivered-To: ray.paseur@gmail.com
Received: by 10.216.157.196 with SMTP id o46cs18294wek;
        Mon, 7 Mar 2011 12:22:08 -0800 (PST)
Received: by 10.150.69.3 with SMTP id r3mr4989488yba.280.1299529327265;
        Mon, 07 Mar 2011 12:22:07 -0800 (PST)
Return-Path: <gdcscom@bracey.site5.com>
Received: from bracey.site5.com (bracey.site5.com [174.120.252.82])
        by mx.google.com with ESMTPS id n12si460187ybk.96.2011.03.07.12.22.06
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 07 Mar 2011 12:22:07 -0800 (PST)
Received-SPF: pass (google.com: best guess record for domain of gdcscom@bracey.site5.com designates 174.120.252.82 as permitted sender) client-ip=174.120.252.82;
Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of gdcscom@bracey.site5.com designates 174.120.252.82 as permitted sender) smtp.mail=gdcscom@bracey.site5.com
Received: from gdcscom by bracey.site5.com with local (Exim 4.69)
	(envelope-from <gdcscom@bracey.site5.com>)
	id 1PwgwQ-0004GG-04
	for Ray.Paseur@Gmail.com; Mon, 07 Mar 2011 14:22:06 -0600
To: Ray.Paseur@Gmail.com
Subject:  An inquiry from Jerry Pinzino
X-PHP-Script: gdcs.com/contact_us.php for 76.217.35.201
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
From: gpinzino@att.net
Message-Id: <E1PwgwQ-0004GG-04@bracey.site5.com>
Date: Mon, 07 Mar 2011 14:22:06 -0600
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - bracey.site5.com
X-AntiAbuse: Original Domain - gmail.com
X-AntiAbuse: Originator/Caller UID/GID - [2046 32008] / [47 12]
X-AntiAbuse: Sender Address Domain - bracey.site5.com
X-Source: /usr/bin/php
X-Source-Args: /usr/bin/php /home/gdcscom/public_html/contact_us.php 
X-Source-Dir: gdcs.com:/public_html

 Monday, March 7, 2011, 2:22 pm <p>

        Message: Ray,
Here is an email message for you to review. Let me know what you see. By the way, My email routine is pretty close to what you sent me. I did take some of your code and adapt it to what I already had.

Looking forward to hearing from you.

Jerry <p>

        From: Jerry Pinzino <p>

        Email: gpinzino@att.net<p>

		Phone:

Open in new window

0
 
gpinzinoAuthor Commented:
I will study your response in detail. Thanks for your help.
0
 
gpinzinoAuthor Commented:
Ray, how do you know the return path and the from address are on different servers? I see an IP for the return-path, (bracey.site5.com [174.120.252.82]), but not for the from address (gpinzino@att.net). Am I looking at the wron information?
0
 
Dave BaldwinFixer of ProblemsCommented:
att.net servers are in the range 216.76.0.0 - 216.79.255.255 which isn't 174.120.252.82.  Isn't 'bracey.site5.com' your web server?  Just as I looked this up, mail servers some times look them up too to see if the email address is a 'valid' one... according to their spam filter.
0
 
Ray PaseurCommented:
What DaveBaldwin said!
0
 
gpinzinoAuthor Commented:
I'm going to call Charter today and try to get to the bottom of this.
0
 
gpinzinoAuthor Commented:
I got it! I finally gave up on the PHP mail() function since the recipient's email service did not like what I was doing. I rewrote the page incorporating PHPMailer as vivalmaria suggested, and it worked on the first try! Thanks also to Ray Passeur for your patience, hands-on assistance and insightful suggestions. Finally, thanks to DaveBaldwin for your insights.

You guys are the best!
0
 
gpinzinoAuthor Commented:
Enail is a challenge in the best of circumstances, and the contributions made by the experts all contributed to the insights needed to resolve the issue. Overall, they did a fine job.
0
 
Ray PaseurCommented:
Why did you mark our answers down a whole letter grade without even giving us a chance to correct the deficiencies?  What did we do wrong?
0
 
gpinzinoAuthor Commented:
Ray,
I am sorry I upset you with my grade. I am fairly new to Experts Exchange and am not familiar with how users grade responses. You tried very hard and stayed with it to the end, and I definitely would have given you an A if the grading were on an individual basis. My impression was that an A was reserved for an effort that provided a complete and successful solution. What I received from some of the others were quick suggestions and not solutions in themselves. You were the only one that offered code as a possible solution. I got the impression that most of the others did not even look at my code. You, and to a lesser extent, DaveBaldwin, were the only two that hung in there and continued to offer assistance. I gave you additional points for your obvious conern and persistance in trying to provided a solution. In retrospect, I should have raised your points even more. Now that I understand what an important issue the grade is, I will be more generous next time.
0
 
Ray PaseurCommented:
Thanks, gpinzino.  

You may find over time that some answers at EE are tested solutions and some are just educated guesses.  You will also learn who provides what!  

DaveBaldwin, BPortlock, Roads Roads, hielo, angelIII, jason1178 all seem pretty heads-up to me.  Not to take anything away from the others who toil in this forum, but those guys are some of the ones who seem to provide the most insight and understanding.

All the best, ~Ray
0
 
Dave BaldwinFixer of ProblemsCommented:
Thanks Ray, but you are seriously more organized than I am.!
0
 
Ray PaseurCommented:
;-)
0
 
gpinzinoAuthor Commented:
Well, you are both great guys in my book! Thanks for being active participants in such a great service.
0
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 13
  • 9
  • 5
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now