Solved

Problem sending email via PHP

Posted on 2011-03-08
6
290 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Andy Brown
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks MunterMan - I appreciate your help on this one.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

763 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

13 Experts available now in Live!

Get 1:1 Help Now