Home > Back-end >  PHP mail function page not opening
PHP mail function page not opening

Time:12-14

I am trying to send an email from my live server (Godaddy hosting) using the PHP mail function I have written the script but when I am trying to open the mail.php file on my browser it isn't opening and throws an error This page isn’t working prac.shayankanwal.com is currently unable to handle this request. HTTP ERROR 500 (I am not using any forms just directly opening that file) also, it is not Sending the email I have been trying to figure this out for the last 6 hours reading about that issue on StackOverflow but nothing seems to work also, another thing Does this mail function works without an SSL certificate or not?

here is the link to live server and below is the script I have written which is also on the live server

<?php

$to = "[email protected]";
$subject = "Test mail";
$message = "Hi This is  a test email you received from server";
$from = "[email protected]";
$headers = "From: $form";
if(mail($to,$subject,$message,$headers)){
    echo "Email sent";
}else{
    echo "Email NOT sent"
}

?>

CodePudding user response:

FATAL ERROR syntax error, unexpected token "}", expecting "," or ";" on line number 12

You have missed a ; on line 12

}else{
    echo "Email NOT sent";
}

Also you have a Typo on line 7:

$headers = "From: $form";

should be:

$headers = "From: $from";

The restored code should look like this:

<?php

$to = "[email protected]";
$subject = "Test mail";
$message = "Hi This is  a test email you received from server";
$from = "[email protected]";
$headers = "From: $from";
if(mail($to,$subject,$message,$headers)){
    echo "Email sent";
}else{
    echo "Email NOT sent";
}

?>

Keep in mind that DEBUGGING in php is simple by adding the following lines to the top of your code (below <?php ofcourse.):

error_reporting(E_ALL);
ini_set("display_errors", 1);

Error 500's are Internal Server Errors (Fatal Errors), meaning there is a mistake in your code. You can debug them by using the code above.

  • Related