gpt4 book ai didi

php - 如何修复 sendmail.php 不起作用?

转载 作者:行者123 更新时间:2023-11-28 01:09:03 24 4
gpt4 key购买 nike

我有网站,我不是专业人士,但我已经完成了,除了 sendmail 问题。当我单击“立即发送”按钮时,屏幕上会显示“感谢您的消息”消息,但我没有收到任何电子邮件。

  • 我检查了垃圾邮件箱它也没有

  • 我检查了 phpinfo SMTP 端口打开和 25

  • 我检查了 phpinfo senmail_path/usr/sbin/sendmail -t -i

  • 我调用托管公司并发送了电子邮件,他们说一切正常服务器端检查您的 sendmail 脚本。

这里是sendmail.php文件;

<?php
$name = @trim(stripslashes($_POST['name']));
$from = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
$to = 'tradertarik@gmail.com';

$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();

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

我需要帮助找出问题所在。我检查了其他问题并以某种方式回答了它对我没有帮助。提前致谢。

P.S. 我不确定是否有人需要表单 html 代码,但我认为添加它也很好。

    <div class="contact-form wow fadeIn" data-wow-duration="1000ms" data-wow-delay="600ms">
<div class="row">
<div class="col-sm-6">
<form id="main-contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="row wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Name" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email Address" required>
</div>
</div>
</div>
<div class="form-group">
<input type="text" name="subject" class="form-control" placeholder="Subject" required>
</div>
<div class="form-group">
<textarea name="message" id="message" class="form-control" rows="4" placeholder="Enter your message" required></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn-submit">Send Now</button>
</div>
</form>
</div>

最佳答案

您的$headers 参数不正确;它应该是 string 而不是 array。来自PHP manual :

String to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.

您应该能够像这样解决问题:

mail($to, $subject, $message, implode("\r\n", $headers));

关于php - 如何修复 sendmail.php 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38453531/

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