簡體   English   中英

PHP 郵件 function 頁面打不開

[英]PHP mail function page not opening

我正在嘗試使用 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 (我沒有使用任何 forms 只是直接打開該文件)它也沒有發送 email 我在過去 6 個小時里一直在努力解決這個問題,在 StackOverflow 上閱讀了有關該問題的信息,但似乎也沒有任何效果,另一件事 這個郵件 function 是否在沒有 SSL 證書的情況下工作?

這是實時服務器的鏈接,下面是我編寫的腳本,它也在實時服務器上

<?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語法錯誤,意外標記“}”,應為“,”或“;” 在第 12 行

你錯過了一個; 12號線

}else{
    echo "Email NOT sent";
}

另外,您在第 7 行有錯別字:

$headers = "From: $form";

應該:

$headers = "From: $from";

恢復后的代碼應如下所示:

<?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";
}

?>

請記住,在 php 中進行調試很簡單,只需將以下幾行添加到代碼頂部即可(當然在<?php下方。):

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

錯誤 500 是內部服務器錯誤(致命錯誤),這意味着您的代碼中存在錯誤。 您可以使用上面的代碼調試它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM