Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 (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"
}

?>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading