Heya. I have a problem with a mail script. It returns no error or anything it just doesn't send.

if(mail($email, "Test", $mess, "From: $nick <$email>")){echo 'Mail sent!';}else{echo 'Mail failed';}

Sorry if the code looks confusing, I can write better but I've rewritten it so many times to get it to work but it just simply won't.

P.S. The variables got values, allready checked that. D.S.

7 Years
Discussion Span
Last Post by cwarn23

Well the mail script behind the scenes isn't as simple as it sounds. From what I have read in the manual some time ago, testing the mail function in an if statement only tests what may have gone wrong on the php side of things. If it passes that if function and doesn't send then it is more likely to be an incorrect server configuration or a fatal network error when transmitting the email. So if you are just using the above script as a test script and the mail function never works I would suggest sending an email to your web hosting company with a copy of the script as proof. So probably find just a misconfiguration on your server.


Thank you.

I just realized that I forgot to mention that it never passes the if.. When I run the code above the output simply is "Mail Failed".


Then with that extra info, I would suggest using the following as a test script untill things a right. So just make the following as a new php file and configure the first two variables. Also make sure both emails are different and valid as a test.

$mess='It works';
if(mail($email, 'Test', $mess, "From: ".$secondemail)){echo 'Mail sent!';}else{echo 'Mail failed';}

Also if the above code doesn't work normally it is the php.ini settings that need changing. If you are using the script under localhost (on your local machine and not a server) then you may find the php.ini file is a real devil to configure the mail function. But normally on a web host these settings are pre configured.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.