?
Solved

Problem sending email via PHP

Posted on 2011-03-08
6
Medium Priority
?
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

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