Solved

Problem sending email via PHP

Posted on 2011-03-08
6
299 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 16

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 16

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 16

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to avoid jquery conflicts in Wordpress ? 4 24
Problem with a CSS in a page 2 26
Alignment is not working correctly. 8 32
CSS Logo Problem. 2 7
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

910 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

23 Experts available now in Live!

Get 1:1 Help Now