Learning Learning - 4 months ago 14
PHP Question

PHP mail not working for some reason

I am new to PHP and I'm using the mail function to send emails which is not working. I get a success message, but still it does not work

same code

<?php
$email_to = "abc@abc.com";
$email_subject = "Test mail";
$email_body = "Hello! This is a simple email message.";


if(mail($email_to, $email_subject, $email_body)){
echo "The email($email_subject) was successfully sent.";
} else {
echo "The email($email_subject) was NOT sent.";
}
?>


Am I missing anything, do I need to include any files for this function.. I am from asp.net & this is the basic script which found on website.

I tried other scripts related to mail they didn't work either..

I AM RUNNING THIS SCRIPT ON THE WEBSITE NOT on the localhost

Answer

this is probably a configuration error. if you insist on using PHP mail function, you will have to edit php.ini.

if you are looking for an easier and more versatile option (in my opinion), you should use PHPMailer