简体   繁体   中英

PHP mail function page not opening

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 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 = "shayankanwal667@gmail.com";
$subject = "Test mail";
$message = "Hi This is  a test email you received from server";
$from = "clientsupport@shayankanwal.com";
$headers = "From: $form";
if(mail($to,$subject,$message,$headers)){
    echo "Email sent";
}else{
    echo "Email NOT sent"
}

?>

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 = "shayankanwal667@gmail.com";
$subject = "Test mail";
$message = "Hi This is  a test email you received from server";
$from = "clientsupport@shayankanwal.com";
$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM