PHP 电子邮件在 WIMP 上失败

发布于 2024-11-15 17:04:00 字数 1541 浏览 2 评论 0原文

我有一个 WordPress 网站,其中的联系表单在我的 MAMP 环境中运行良好,但是当我发布到我的客户端 WIMP 服务器时,我遇到了失败。

  • 我对 WIMP 环境一点也不熟悉——如何检查 PHP 错误日志
  • 顺便问一下,WIMP 上的 PHP 电子邮件发送问题是否会导致这种情况?

代码:

<?php 

if ($_POST["contact_name"]<>'') { 
    $ToEmail = '[email protected]'; 
    $EmailSubject = 'New contact message';  
    $mailheader = "From: ".$_POST["contact_email"]."\r\n";  
    $mailheader .= "Reply-To: ".$_POST["contact_email"]."\r\n"; 
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";  
    $MESSAGE_BODY = "<b>Name:</b> ".$_POST["contact_name"]."<br>";  
    $MESSAGE_BODY .= "<b>Email:</b> ".$_POST["contact_email"]."<br>";
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 

?> 
<h4>Your message was sent. We will be in touch with you shortly.</h4>
<?php 
} else { 
<form id="contact-form" name="contact" method="post" action="#">
<label for="contact-name">Name *</label>
<input type="text" id="contact-name" name="contact_name" tabindex="1" class="required"/>
<label for="contact-email">Email</label>
<input type="text" id="contact-email" name="contact_email" tabindex="2" class="email" />
<input type="submit" id="contact-submit" name="contact_submit" value="" tabindex="8" />
</form>
<?php 
}; 
?>

I've got a WordPress site with a contact form that works fine on my MAMP environment, but when I publish to my clients WIMP server I get a failure.

  • I am not at all familiar with WIMP environments- how does one go about checking PHP error logs
  • Offhand, are there issues with PHP emailing on WIMP that would be causing this?

Code:

<?php 

if ($_POST["contact_name"]<>'') { 
    $ToEmail = '[email protected]'; 
    $EmailSubject = 'New contact message';  
    $mailheader = "From: ".$_POST["contact_email"]."\r\n";  
    $mailheader .= "Reply-To: ".$_POST["contact_email"]."\r\n"; 
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";  
    $MESSAGE_BODY = "<b>Name:</b> ".$_POST["contact_name"]."<br>";  
    $MESSAGE_BODY .= "<b>Email:</b> ".$_POST["contact_email"]."<br>";
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 

?> 
<h4>Your message was sent. We will be in touch with you shortly.</h4>
<?php 
} else { 
<form id="contact-form" name="contact" method="post" action="#">
<label for="contact-name">Name *</label>
<input type="text" id="contact-name" name="contact_name" tabindex="1" class="required"/>
<label for="contact-email">Email</label>
<input type="text" id="contact-email" name="contact_email" tabindex="2" class="email" />
<input type="submit" id="contact-submit" name="contact_submit" value="" tabindex="8" />
</form>
<?php 
}; 
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北城孤痞 2024-11-22 17:04:00

Windows 没有像 UNIX 类型操作系统那样内置电子邮件服务器。您需要配置 php.ini 以添加用于中继电子邮件的 SMTP 服务器信息。

Windows does not have a built in email server like unix type OSs tend to have. You need to configure php.ini to add SMTP server information through which to relay email.

毁梦 2024-11-22 17:04:00

`mail()' 函数的 PHP 手册页 详细介绍了许多Windows 特定点。然而,可能影响您的要点在本节中:(引用)

mail() 的 Windows 实现在很多方面与 Unix 实现不同。首先,它不使用本地二进制文件来编写消息,而是仅在直接套接字上运行,这意味着 MTA 需要侦听网络套接字(可以在本地主机或远程计算机上)。

其次,像 From:、Cc:、Bcc: 和 Date: 这样的自定义标头首先不会由 MTA 解释,而是由 PHP 解析。

因此,to 参数不应是 "Something <[电子邮件受保护]>"。与 MTA 通信时,邮件命令可能无法正确解析此内容。

还有其他一些事情需要考虑;请阅读手册页了解更多信息。

希望有帮助。

The PHP manual page for the `mail()' function details a number of Windows-specific points. However, the main points which could affect you are in this section: (to quote)

The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP.

As such, the to parameter should not be an address in the form of "Something <[email protected]>". The mail command may not parse this properly while talking with the MTA.

There are a few other things to consider as well; please read the manual page for more.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文