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 = "[email protected]"; $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
check with your host, many have disabled the mail() function for anti-spam purposes you might need to use smtp instead. The script looks ok. Also the sucess message suggest is a configuration problem... check your configuration... also check the configuration on the receiving server.
to check if it is sending mail as intended; <? php $email = "[email protected]"; $subject = "Email Test"; $message = "this is a mail testing email function on server"; $sendMail = mail($email, $subject, $message); if($sendMail) { echo "Email Sent Successfully"; } else { echo "Mail Failed"; } ?>
On a *nix machine, the PHP mail() function does not support SMTP, but instead uses the sendmail() or other configured mail script on the server. This script can send through an SMTP, but this isn't the easiest way within PHP (unless you already have the script). To use SMTP, I would recommend PHPMailer.
If you are using Ubuntu and it seem sendmail is not in /usr/sbin/sendmail
, install sendmail using the terminal with this command:
sudo apt-get install sendmail
and then run reload the PHP page where mail()
is written. Also check your spam folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With