hi, i have a function that uses the php mail() function but it doesn't seem to be sending the mail. i'm not sure if i have to create the email account in cpanel or not but from what i've seen, it doesn't uses SMTP. ive seen many simple tutorials online and this is as simple as it gets but i guess not simple enough for my script to work. anyone knows what is wrong? or how i can fix this? function smail($post) { $to = $post['email']; $subject = "activation code"; $message = "Activation code: ".$post['activationcode']; $from = "activate@mywebsite.com "; $headers = "From: $from"; if(mail($to, $subject, $message, $headers)) { echo 'success'; } else { echo 'deny'; } } PHP:
What PHP error or warning do you get? If none then turn warnings and errors on, this will be very useful information and it will be easier for us to help you.
You might need more mime info in the headers, but I don't think this will stop the mail function from sending the message. I've always used the folowing to build the headers and have never had a problem. You should also correct all of the other issues that people identified. $headers = ""; $headers .= "From: $from\n"; $headers .= "Reply-To: $from\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\n"; Try displaying all of your variable values before script reaches the mail function. Something is not being fed correctly. I suspect that the $to value is missing.
If you have a firewall, check that you didn't firewall off the ports it uses to send the mail. I think I might have done that to mine yesterday..
You can try to contact support on your hosting about this issue. Also can you look your php.ini file and look section about sendmail. Also you can use phpinfo() function. Can you say what you have near following variable sendmail_path ?
This is my sendpath output from phpinfo() sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i All the variables I outputted onto the screen and it's correctly filled in. The mail doesn't sends though.
SO please try to contact hoster support. They can look sendmail log and say does this problem with sendmail ot this is problem with your code.
Sometimes the hosting does not allow php to send emails, although php does not show any error but it does not work. They disable this function to prevent from misuse in the form of spam. Sometimes they only allow it to be used for the same domain emails like, if your domain is world.net the script will only work if the recipient and sender email in the function is @world.net Confirm from your hosting provider.