简体   繁体   English

PHP 邮件 function 页面打不开

[英]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我正在尝试使用 PHP 邮件从我的实时服务器(Godaddy 托管)发送一个 email 邮件 function 我已经编写了脚本但是当我试图在我的浏览器上打开 mail.php 文件时它没有打开并抛出错误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? This page isn't working prac.shayankanwal.com is currently unable to handle this request. HTTP ERROR 500 (我没有使用任何 forms 只是直接打开该文件)它也没有发送 email 我在过去 6 个小时里一直在努力解决这个问题,在 StackOverflow 上阅读了有关该问题的信息,但似乎也没有任何效果,另一件事 这个邮件 function 是否在没有 SSL 证书的情况下工作?

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 ";" FATAL ERROR语法错误,意外标记“}”,应为“,”或“;” on line number 12在第 12 行

You have missed a;你错过了一个; on line 12 12号线

}else{
    echo "Email NOT sent";
}

Also you have a Typo on line 7:另外,您在第 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.):请记住,在 php 中进行调试很简单,只需将以下几行添加到代码顶部即可(当然在<?php下方。):

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.错误 500 是内部服务器错误(致命错误),这意味着您的代码中存在错误。 You can debug them by using the code above.您可以使用上面的代码调试它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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