Problem with mail()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Problem with mail()

Post 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.
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: Problem with mail()

Post 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
lettie_dude
Forum Commoner
Posts: 65
Joined: Thu Dec 07, 2006 10:10 am

Re: Problem with mail()

Post 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.
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Problem with mail()

Post by jraede »

Lettie_dude, you're a life saver. Don't know why that worked, and don't really care, but thanks a lot.
Post Reply