Page 1 of 1

Problem with mail()

Posted: Thu Aug 12, 2010 6:18 am
by jraede
For some reason the mail function has stopped working on a client's server...I'm not familiar enough with how it functions that I can narrow down the issue. It returns TRUE, but I am not receiving the e-mail in my test code. What steps should I take to narrow down the problem? I've read somewhere that it's a problem either with the php.ini setting for sendmail or sendmail itself, but I have no idea how to fix that, or even if that is indeed the problem.

My code is this:

Code: Select all

$mailed = mail('my-email@my-host.com', 'test', 'test body');
echo ($mailed) ? 'Mailed successfully' : 'Failure';
I see "mailed successfully" when I load the page, but it's not sending to my e-mail. I've checked multiple times to make sure I'm typing it correctly, so I doubt it's any stupid mistake like that. Any help would be appreciated.

Re: Problem with mail()

Posted: Thu Aug 12, 2010 6:23 am
by PHPHorizons
Hello jraede,

mail() pretty much always returns true because PHP just takes the mail and attempts to hand it off to the mail server. It doesn't check to see what the mail server does with that mail.

Has the web host for your client been contacted yet? They can check the mail logs to see what is going on.

Cheers

Re: Problem with mail()

Posted: Thu Aug 12, 2010 7:16 am
by lettie_dude

Code: Select all

ini_set ("sendmail_from", "from@yourdomain.co.uk");
$fromemail = "from@yourdomain.co.uk"; 
$mime = "MIME-Version:1.0\r\nContent-type:text/html;Charset=iso-8859-1\r\nFrom: ".$fromemail;
@mail("to@whoever.co.uk","Subject",'Content',$mime,"-f$fromemail");
Try the above. I had a similar problem with a hosting company previously changing their settings and not informing anyone! I'm not completely sure what the -f bit does but I need to add it to validate the from address.

Re: Problem with mail()

Posted: Thu Aug 12, 2010 11:55 am
by jraede
Lettie_dude, you're a life saver. Don't know why that worked, and don't really care, but thanks a lot.