I'm quite new to PHP. I've just built my first PHP form handler that will save the form data to a text file on my server and then email me an alert, but the Mail() function isn't sending me the email. I have set it to send to my gmail account but I don't receive it in my inbox or spam.
How can I make it email me properly?
You need to make sure PHP is connect to the email server. The conifuration would be in the PHP.ini file. If your running this off your home computer then you probably don't have an email server setup. If you have a hosting plan, they already have this configured for you and you can use the mail() function all day long.
Thanks for the reply HP400. I am using a free webhost (100webspace.com)
Where can I locate this php.ini? Isn't there a function to get all the php info (I remember using it a while ago)
How can I connect it to the mail server? Thanks, raZer
Well they do have email service so I don't see why you shouldn't be able to email. The php.ini (windows configuration) would be located on the server and you won't have access to it. What does your mail code look like?
<? mail("shirazamod@gmail.com", "Mail Sent By PHP", "This message was sent by php") ?>
That's it
Hmmmm looks perfect (minus the missing ; at the end). Why don't you try an if around it to see if it is sending.
if (mail("shirazamod@gmail.com", "Mail Sent By PHP", "This message was sent by php") ) echo "Sent!!!!"; else echo "Dang It!";
It says that it was sent.
There really shouldn't be a problem then...I've seen hosting companies email servers get backed up and sometimes its taken half a day for the email to come. Since your on a free hosting site it might be just that. The PHP side of things looks fine so if you don't get something by tomorrow then I'd say email your hosting companies tech support.
I've tried this same code yesterday, so it isn't a delay. I'm not getting it.
Do you know if gmail blocks something sent by Mail() because of spam or something? Do you know of a free webhost where I can try host this file?
OK I've found that the problem is that they dont allow you to send mail to any other email service apart from theirs
To make it more secure read this: http://securephp.damonkohler.com/index.php/Email_Injection