【问题标题】:php form not sending info via email about 30% of timephp 表单大约 30% 的时间没有通过电子邮件发送信息
【发布时间】:2012-05-11 18:49:53
【问题描述】:

在大约 30% 的访问者填写表单的情况下,我会收到“此消息没有内容”错误,并且无法确定问题所在。下面是用于发送电子邮件的 php,地址是匿名的。有什么想法吗?

到目前为止,我已尝试在论坛中找到答案,但无济于事。感谢您的帮助!

<?php

    $fromAddress = 'x@www.com';
    $subject = 'Resources - White Paper Download - '.$_POST['WhitePaper'];

    $message .= "\r\n";

    foreach($_POST as $name => $value) {
    $message .= $name . ': ' . $value . "\r\n";
    }

    $to       = 'y@www.com';
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
    $headers .= 'From: ' . $fromAddress . "\r\n" .
        'Reply-To: ' . $fromAddress . "\r\n" .
        'X-Mailer: PHP/' . phpversion(). "\r\n";
    $headers .= 'Cc: z@www.com, <t@www.com>' . "\r\n";
    mail($to, $subject, $message, $headers);
    echo "mail sent";
?>

【问题讨论】:

  • 请注意,如果 $fromAddress 来自用户输入,请确保从中删除任何换行符,否则您很容易受到电子邮件注入。
  • 查看表单的代码可能会有所帮助

标签: php forms email


【解决方案1】:

如果您无法发现任何一致的内容(即某些链接是否总是失败,或者它们有时会起作用?)那么我只能建议您在代码中添加尽可能多的日志记录,然后查看如果有模式。

创建一个日志文件,每次调用您的邮件代码时,将电子邮件的详细信息写入其中,以及服务器的响应;然后检查并在看到错误出现时查看是否可以复制问题。

我能看到的唯一可能导致它的原因是 $_POST 为空 - 我假设您总是以相同的方式调用脚本,并且您永远不会使用 _GET 参数集链接到它?

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多