gpt4 book ai didi

php - 电子邮件功能在 Linux(vps) 服务器上不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 04:29:30 24 4
gpt4 key购买 nike

我正在 Linux (vps) 服务器上测试电子邮件功能。这是我正在使用的以下代码:

<?php
// --- CONFIG PARAMETERS --- //
//
$email_recipient = "recipient@demo.com";
$email_sender = "Sender Name";
$email_return_to = "sender@demo.com";
$email_content_type = "text/html; charset=us-ascii";
$email_client = "PHP/" . phpversion();
//
// ------------------------- //

// --- DEFINE HEADERS --- //
//
$email_header = "From: " . $email_sender . "\r\n";
$email_header .= "Reply-To: " . $email_return_to . "\r\n";
$email_header .= "Return-Path: " . $email_return_to . "\r\n";
$email_header .= "Content-type: " . $email_content_type . "\r\n";
$email_header .= "X-Mailer: " . $email_client . "\r\n";
//
// ---------------------- //

// --- SUBJECT AND CONTENTS --- //
//
$email_subject = "Test email subject";
$email_contents = "<html>";
$email_contents .= "<h2>Test Email</h2>";
$email_contents .= "<br><b>Sender: " . $email_sender;
$email_contents .= "<br><b>Recipient: " . $email_recipient;
$email_contents .= "</html>";
//
// ---------------------------- //

$email_result = mail($email_recipient, $email_subject, $email_contents, $email_header);
if ($email_result) echo "Email has been sent!";
else echo "Email has failed!";
?>

当我执行代码时,需要很长时间才能处理,然后显示电子邮件已发送。但电子邮件永远不会发送给收件人。我已通过 phpinfo() 函数显示的 php.ini 文件中的发送电子邮件路径进行了检查:

 sendmail_from  no value    no value
sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i

我无法查出原因。

请帮我解决这个问题。

谢谢

潘卡杰

最佳答案

使用实际的电子邮件地址作为$email_sender;如果不起作用,请在 mail() 函数中写入第五个参数 -fsenderemail@mail.com (无论发件人电子邮件是什么)

关于php - 电子邮件功能在 Linux(vps) 服务器上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4919147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com