Jump to content

I can't figure out what is wrong with this mail() script.


artech

Recommended Posts

Okay, so I have a page that needs to email the site administrator. The message is hard coded, the recipient and headers are hard coded. Nothing from the user.

 

The code is up on the client's server, working great. I get the email right away, every time. Ran the page a large number of times and never missed a message.

 

So I change my email value to the email address of the administrator. No email. No errors.

 

So I move the script onto my server and run it. He gets the email. I get the email.

 

I am terribly frustrated and these guys are up against a deadline, which is adding to my stress.

 

Anyone have an idea of what is going wrong?

 

The script is as follows (strings and emails are sterilized).

 

# here is the email script that is messing with me
# thanks for taking a look!
# ----------------------------------------------------#

// send email notification to site administrator

// start setting up the email
$from= "no-reply@the-site-domain.com";
$to= "administrator@administrators-email-domain.com";
$subject = "Email Notification";

// create the text for the message body
$message = "string text for line 1\n";
$message .= "string text for line 2\n";
$message .= "string text for line 3\n\r";
$message .= "This email was generated on ".date('Y-m-d H:i:s');

// now start a while wrapper to make sure we try 
// sending the email until it succeeds
while (!$mail) {
$mail = mail($to, $subject, $message,
	 "From: ".$from." <".$from.">\r\n"
	."Reply-To: ".$from."\r\n"
	."X-Mailer: PHP/" . phpversion());
}

 

 

Link to comment
Share on other sites

I'll take the suggestion of opening a support ticket. At least on the surface, the server configurations are the same, but I know that 'on the surface' doesn't count for much with third party hosts. I updated the config files I have access to to match their server.

 

Do you have any ideas of what kind of error could possibly be making their server succeed when sending the email to my address but fail when sending to either of the administrator's email addresses?

 

Thanks a bunch!

Link to comment
Share on other sites

For debugging purposes, turn on full php error reporting/display. Add the following two lines of code after the first opening <?php tag -

ini_set("display_errors", "1");
error_reporting(E_ALL);

 

For each of the servers where you tried this, where are both the To: and From: email address hosted at relative to the sending mail server?

 

About the only thing that putting the mail() function in a while(){} loop will accomplish is getting the web host upset at you and suspending your hosting account. If an error is occurring, that will just make an infinite loop connecting to the sending mail server and passing it the same values over and over until the php script times out.

Link to comment
Share on other sites

For debugging purposes, turn on full php error reporting/display. Add the following two lines of code after the first opening <?php tag -

ini_set("display_errors", "1");
error_reporting(E_ALL);

No errors, even with full report/display turned on. :(

For each of the servers where you tried this, where are both the To: and From: email address hosted at relative to the sending mail server?

Client Server: MediaTemple

My Server: GoDaddy

 

My email # 1

  • Hosted at a University
  • Same university that hosts Client email #1
  • Not hosted by the sending mail server

 

My email #2

  • Hosted at my GoDaddy server
  • Not hosted by the sending mail server

 

Client email #1

  • Hosted at a University
  • Same university that hosts My email #1
  • Not hosted by the sending mail server

 

Client email #2

  • Hosted at client's MediaTemple server
  • Is hosted by the sending mail server

 

Outcome:

I receive the email notification regardless of address and regardless of sending mail server.

My client receives the email notification when the script is hosted on my server but does not receive the email notification when the script is hosted on their server.

About the only thing that putting the mail() function in a while(){} loop will accomplish is getting the web host upset at you and suspending your hosting account. If an error is occurring, that will just make an infinite loop connecting to the sending mail server and passing it the same values over and over until the php script times out.

Thanks for the tip!

Link to comment
Share on other sites

not with the documentation

try this

telnet <hostname or ip> 25

 

if this shows some results then port is opened..

or else if it gives some thing like this then the port is closed..

Connecting To <ip address>...Could not open connection to the host, on port 25: Connect failed

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.