Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail not working for some reason

Tags:

php

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

like image 250
Learning Avatar asked Jan 10 '12 13:01

Learning


People also ask

Why is my mail PHP not working?

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.

How do you check PHP mail function is working or not?

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"; } ?>

Does PHP mail need SMTP?

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.


1 Answers

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.

like image 160
Prabhat Kashyap Avatar answered Sep 23 '22 08:09

Prabhat Kashyap