簡體   English   中英

PHP Mail() 函數在 cpanel 托管中不起作用

[英]PHP Mail() function not working in cpanel hosting

PHP mail()函數在我的 cpanel 中不起作用。

我的 cpanel 端口都是打開的,默認情況下,電子郵件 ID 也在 cpanel 中設置。

我的代碼

$to = "rahul@gmail.com";
$subject = "My subject"; 
$txt = "Hello world!";
$headers = "From: webmaster@host4future.in" ;
mail($to,$subject,$txt,$headers);

您的代碼似乎是正確的,但大多數主機默認阻止郵件功能和/或阻止用戶nobody 發送電子郵件。

WHM 的 Tweak Settings 中,嘗試關閉“Prevent 'nobody' from send mail”選項。

PHP 配置編輯器(在高級模式下)檢查郵件功能是否列在disable_functions指令中。

如果這些都不起作用,請檢查Exim是否啟動並運行,以及php.ini 中的 sendmail_path是否正確。

就我而言,有一個 apache 配置錯誤。 我在日志中只看到了這個unable to set gid=993 or uid=0 (euid=0): forcing real = effective修復方法是將LimitUIDRange 0 2000添加到 apache mpm_prefork.conf 文件並重新啟動 apache

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

$from = "adfghh@gmail.com";
$to = "lthser@gmail.com";

$subject = "PHP Mail Sending Checking";
$message = "PHP Mail Works Fine";
$headers = "From: " . $from;

mail($to,$subject,$message,$headers);

暫無
暫無

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

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