Jump to content

mail() not working, options for finding out why?


rich_traff

Recommended Posts

Hi, i've written a script that use's mail() in it to send some information. I've tested this on my own server and it works fine, however when i put it onto a clients server the email does not come through.

 

Here is the email part of the script

<?php

$to = "me@example.com";
$subject = "subject";
$body = "Body of email";

$email_from = "Example";
ini_set("sendmail_from", $email_from);
$headers = "From: $email_from";

	if (mail($to, $subject, $body, $headers)) 
{
   		echo("<p>Your email has been sent</p>");
}            	
    else 
{
	echo("<p>An error has occured</p>");
}

So on my own server, the script runs, the message "Your email has been sent" shows and i receive the email.

 

On my clients server, the script runs, the message "Your email has been sent" still shows, i do not get an error message, but the email never gets received.

 

So im assuming it must be a config issue with their server…

 

A problem though is that i only have ftp details for it and currently no way of contacting the web host, i don't even know where its hosted, all i have is a host ip, username and password.

 

So, i am looking for some advice on

A) what i should be looking for to figure out why the email is not getting through

B) how to go about finding that info?

C) options for improving the script that will ensure the email is sent/received..

 

Can anyone offer any advice?

 

Link to comment
Share on other sites

Are there no files called error_log in your webserver webroot for example?

 

Maybe something like this in your code will work, depending on what the server allows.

ini_set('error_reporting', E_ALL);

 

Since mail() relays it's requests through sendmail check those logs, too - no way for you to access those though /var/log/mail.log.

 

You could see whether an e-mail is actually sent with this kind of script:

http://www.howtoforge.com/how-to-log-emails-sent-with-phps-mail-function-to-detect-form-spam

 

let us know how it turns out

Link to comment
Share on other sites

I tried setting error reporting by placing it in with the mail part of the script

<?php
$email_from = "Example";
ini_set("sendmail_from", $email_from);
ini_set('error_reporting', E_ALL);
$headers = "From: $email_from";

No errors showed though, would it make a difference where i placed it?

 

Also i looked in the error_log file from the site root but found nothing there. the last entry was from a few days ago and detailed some missing css files, there's nothing recent that suggests anything to do with mail or the script i have written.

 

Am still to try the mail log script you suggested

Link to comment
Share on other sites

I tried setting error reporting by placing it in with the mail part of the script

<?php
$email_from = "Example";
ini_set("sendmail_from", $email_from);
ini_set('error_reporting', E_ALL);
$headers = "From: $email_from";

No errors showed though, would it make a difference where i placed it?

 

Also i looked in the error_log file from the site root but found nothing there. the last entry was from a few days ago and detailed some missing css files, there's nothing recent that suggests anything to do with mail or the script i have written.

 

Am still to try the mail log script you suggested

what are the SMTP settings in the php.ini file of the clients server?

also, as the manual states.

 

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

 

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

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.