Solved

Problem sending email via PHP

Posted on 2011-03-08
6
310 Views
Last Modified: 2012-05-11
I have a really strange (urgent) issue in relation to sending an email via a php script.

I need to know if the mail() part of this script can send an email to any location (even if it is on another domain).  I just setup a test scinearo where I had the php script on our server and had the email sent to me, which worked fine.  I then changed the mail address to my clients email address - and the emails didn't get though.

Any ideas?
<?php
$subject = "TEST: " . $_GET['ID'] . "-" . date("Ymd H:i:s");
mail("test@ourdomain.com",$subject,"", "From: test@ourdomain.com");
header("Refresh: 0; URL=" . $_GET['Hyperlink'] . "");
?>

Open in new window

0
Comment
Question by:Andy Brown
  • 3
  • 3
6 Comments
 
LVL 17

Expert Comment

by:Chris Harte
ID: 35068255
Put the mail() inside a conditional. If it returns true then it was sent for delivery and the fault is with the address. If it returns false, there is a problem with your email server.

if (mail("test@ourdomain.com",$subject,"", "From: test@ourdomain.com"))
    echo " worked ";
else
    echo " failed ";
0
 

Author Comment

by:Andy Brown
ID: 35068352
It's odd.  When I run the php script on our server it works every time (both your MunterMan's suggestion and our original script).  However, when we move it over to the clients side it seems intermittent.
0
 
LVL 17

Expert Comment

by:Chris Harte
ID: 35068389
If it is intermittent it is probably timing out due to a connection problem. Also, check the load on the email server to make sure it is not doing anything else while you are trying to send your message.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:Andy Brown
ID: 35068472
Thanks again for your help.

It's tricky as we are based in the UK and the clients webserver is based in the US (and run via a third party).  Also, when we ran the initial tests a few weeks ago it was consistent (and we have other clients using this same script without any issues).  Also, something is telling me (although nobody has called me back to confirm), that their server is using Wordpress (and possibly a Wordpress server), which I know was under attack last week - I'm wondering if that might also be the issue.

0
 
LVL 17

Accepted Solution

by:
Chris Harte earned 500 total points
ID: 35068656
Definitely. If the server is being used to send spam you may well have a queue of messages tens of thousands long, especially if you have spam filters in place. Just because the spam has not been sent does not mean it has been deleted.

The problem is with this client, the script works with other clients so you know there is no problem with the script. Bounce it back and tell them to sort their server out. I gave up on wordpress after about two minuets, so I can not help you with that.
0
 

Author Closing Comment

by:Andy Brown
ID: 35068710
Thanks MunterMan - I appreciate your help on this one.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

770 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