Solved

Email issue - Sends to some addresses and not others.

Posted on 2011-03-03
30
488 Views
Last Modified: 2012-05-11
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
Comment
Question by:gpinzino
  • 13
  • 9
  • 5
  • +3
30 Comments
 
LVL 6

Expert Comment

by:MISOperations
ID: 35031961
Add the address that it is coming from to the exception list in their email, it could be getting blocked.
0
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 100 total points
ID: 35032033
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
 
LVL 1

Author Comment

by:gpinzino
ID: 35032085
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
 
LVL 19

Expert Comment

by:billmercer
ID: 35032087
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
 
LVL 1

Author Comment

by:gpinzino
ID: 35032143
Bill,
Thanks for your input. If Dave's fix doesn't do it, I will try telnet option.
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 200 total points
ID: 35032361
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
 
LVL 7

Accepted Solution

by:
Vimal DM earned 200 total points
ID: 35034089
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
 
LVL 1

Author Comment

by:gpinzino
ID: 35037710
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35038159
I think DaveBaldwin's comment at http:#35032033 is right on, too.
0
 
LVL 1

Author Comment

by:gpinzino
ID: 35060183
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
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 35060421
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35060475
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
 
LVL 1

Author Comment

by:gpinzino
ID: 35060533
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35060769
Have you sent it yet?  I have seen nothing, even in spam.
0
 
LVL 1

Author Comment

by:gpinzino
ID: 35060876
Yes, it went out a few minutes ago.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35061180
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
 
LVL 1

Author Comment

by:gpinzino
ID: 35061292
I will study your response in detail. Thanks for your help.
0
 
LVL 1

Author Comment

by:gpinzino
ID: 35062579
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
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 35062657
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35062685
What DaveBaldwin said!
0
 
LVL 1

Author Comment

by:gpinzino
ID: 35069970
I'm going to call Charter today and try to get to the bottom of this.
0
 
LVL 1

Author Comment

by:gpinzino
ID: 35073334
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
 
LVL 1

Author Closing Comment

by:gpinzino
ID: 35073408
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35075588
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
 
LVL 1

Author Comment

by:gpinzino
ID: 35083043
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35086738
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
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 35086779
Thanks Ray, but you are seriously more organized than I am.!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35086858
;-)
0
 
LVL 1

Author Comment

by:gpinzino
ID: 35087064
Well, you are both great guys in my book! Thanks for being active participants in such a great service.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 35087161
You're welcome, glad to help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now