Link to home
Start Free TrialLog in
Avatar of Andy Brown
Andy BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Problem sending email via PHP

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

Avatar of Chris Harte
Chris Harte
Flag of United Kingdom of Great Britain and Northern Ireland image

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 ";
Avatar of Andy Brown

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Chris Harte
Chris Harte
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks MunterMan - I appreciate your help on this one.