I have a form on my website where users can type a message and their email, and it will be sent to my address. I have installed PHPMailer for another task, but I am using PHP's built in mail()
function because I thought it would work better as it's only a simple task.
However, it does not seem to be working - emails are not sent. Here is my code:
$to = "myemail@gmail.com";
$subject = "Email from " . $_POST["name"];
$txt = $_POST["message"];
$headers = "From: " . $_POST["email"];
if (mail($to, $subject, $txt, $headers)) {
// Success
} else {
// Failed
}
Everything is posted correctly, it's just the mail()
function that returns false. Why is this happening? Should I use PHPMailer instead?
No comments:
Post a Comment