[英]PHP mail function is not working in aws ec2
我正在嘗試在AWS Windows Server 2016中實現PHP郵件功能,但在使用PHP郵件功能后未收到郵件:
<?php
ini_set();
$to = "km.kuldeepmourya@gmail.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";
$check=mail($to,$subject,$txt,$headers);
if($check)
echo"mail sent";
else
echo"mail not sent";
?>
輸出:
Warning: ini_set() expects exactly 2 parameters, 0 given in
C:\xampp\htdocs\mymail.php on line 2
Warning: mail(): Failed to connect to mailserver at "localhost" port 25,
verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in
C:\xampp\htdocs\mymail.php on line 9 mail not sent
除非您在服務器上的php.ini文件中定義sendmail_from
和sendmail_path
,否則mail()
函數在PHP上將始終返回false。 請確保定義了這些值。
有關這些值的更多信息: http : //php.net/manual/en/function.mail.php
如果您無權訪問ini文件,則還可以在php腳本中使用ini_set()
來設置這些值或函數的其他頭文件參數。
快速說明:如果打開警告,則會看到與未定義警告相關的警告。 我建議在開發環境中打開警告,以免將來遇到此類問題。
警告消息告訴您您需要了解的內容。 PHP試圖在本地主機端口25上連接到MTA(郵件服務器)。在該端口上找不到MTA。 這實際上不是PHP問題,而是Windows問題上的郵件服務器。 Windows將其稱為SMTP服務器,因為這是郵件傳輸協議。 您可能需要安裝Windows的郵件服務器,或者安裝Windows Server隨附的打包的SMTP服務器, 如此處所述 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.