简体   繁体   English

PHP mail()奇怪的附加信息自动发送

[英]PHP mail() strange additional information automatically sending

Well, recently, I created a script and placed it up on a domain I have access to. 好吧,最近,我创建了一个脚本并将其放置在我可以访问的域上。 Once I attempted to send an email, the email went through, no problem, but there was a thing that I found strange. 一旦我尝试发送电子邮件,电子邮件就通过了,没问题,但是我发现有些奇怪。

My subject field isn't being set. 我的主题字段尚未设置。 My subject line is completely blank as if I never sent one. 我的主题行完全空白,好像我从未发送过。 It also doesn't seem as if my headers are being sent through either. 好像也不是通过任何一个发送我的标头。 (See this: Image ) (参见此: 图片

Also, is there a reason why these things are sent in the email along with my message? 此外,是否有理由将这些信息与我的信息一起发送到电子邮件中? Like, could it possibly be a setting in php.ini? 就像,可能是php.ini中的设置吗?

Message-Id: message-id-here@**.gs 邮件ID:message-id-here @ **。gs

Date: Wed, 2 Jan 2013 05:37:47 +0400 (MSK) 日期:2013年1月2日,星期三05:37:47 +0400(MSK)

From: www-data@**.gs (www-data) 来自:www-data@**.gs(www-data)

Return-Path: www-data@**.gs 返回路径:www-data@**.gs

X-OriginalArrivalTime: 02 Jan 2013 01:37:47.0814 (UTC) FILETIME=[C5131C60:01CDE889] X-OriginalArrivalTime:2013年1月2日01:37:47.0814(UTC)FILETIME = [C5131C60:01CDE889]

I'm sending an email, and this is the message. 我正在发送电子邮件,这就是消息。

Is this going through correctly? 这是正确的吗?

Currently, this is what my script looks like. 目前,这就是我的脚本的样子。

<html>
<head>
    <title>Email</title>
</head>

<body>
    <?php
        ini_set("mail.add_x_header", "Off");
        if(isset($_POST['send']))
        {
            $To = ((isset($_POST['to'])) ? $_POST['to'] : '');
            $Subject = ((isset($_PST['subject'])) ? $_POST['subject'] : '');
            $Message = ((isset($_POST['message'])) ? $_POST['message'] : '');
            $Headers = ((isset($_POST['from'])) ? "From: " . $_POST['from'] . "\r\n" : '');
            $Headers = ((isset($_POST['reply-to'])) ? "Reply-to: " . $_POST['reply-to'] . "\r\nReturn-Path:" . $_POST['reply-to'] . "\r\n" : '');
            if(mail($To, $Subject, $Message, $Headers))
            {
                echo 'Sent to ' . $To . '.';
            }
        }
    ?>

    <form method="POST">
        To: <input type="text" name="to" value="" /><br />
        Subject: <input type="text" name="subject" value="" /><br />
        Message: <textarea name="message" style="width:300px; height:200px;"></textarea><br />
        From: <input type="text" name="from" value="" /><br />
        Reply-To: <input type="text" name="reply-to" value="" /><br />
        <input type="submit" name="send" />
    </form>
</body>

Your subject isn't set because you have a typo. 您的主题没有设定,因为您有错字。 Change: 更改:

$Subject = ((isset($_PST['subject'])) ? $_POST['subject'] : '');

to: 至:

$Subject = ((isset($_POST['subject'])) ? $_POST['subject'] : '');

As for headers, your Return-To overrides From header. 至于标题,您的Return-To覆盖From标题。 You should also change \\r\\n to \\n as some email clients interpret \\r\\n as "end of all headers". 您还应该将\\ r \\ n更改为\\ n,因为某些电子邮件客户端会将\\ r \\ n解释为“所有标头的结尾”。

So, instead of: 因此,代替:

$Headers = ((isset($_POST['from'])) ? "From: " . $_POST['from'] . "\r\n" : '');
$Headers = ((isset($_POST['reply-to'])) ? "Reply-to: " . $_POST['reply-to'] . "\r\nReturn-Path:" . $_POST['reply-to'] . "\r\n" : '');

Do: 做:

$Headers = array();
if (isset($_POST['from']))
{
    $Headers[] = "From: " . $_POST['from'];
}
if (isset($_POST['reply-to']))
{
    $Headers[] = "Reply-to: " . $_POST['reply-to'];
    $Headers[] = "Return-Path: " . $_POST['reply-to'];
}
$Headers = implode("\n", $Headers) . "\r\n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM