$主题以php邮件形式返回字符串中的第一个单词 [英] $subject in php mail form returning only first word in string

查看:143
本文介绍了$主题以php邮件形式返回字符串中的第一个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习一个web界面类的php,我们的任务之一就是生成一个发送电子邮件的基本形式。然后,我们必须能够通过html在电子邮件中发送该表单的样本。我想这样做显示在发送电子邮件时输入的输入。我有大部分工作,我只是不能得到$ subject变量完全填充在示例中。它只会显示一个单词,并在第一个空格字符之后跳过所有其他单词。 ($ from变量也是如此,但这通常是一个电子邮件地址,因此它不是一个主要问题)



例如,如果我发送电子邮件主题为这是一个测试,当我收到我的收件箱中的电子邮件时,我会在我的电子邮件主题行中看到完整的主题这是一个测试。但是,当我打开电子邮件本身并查看生成的表单样本时,我将只看到This作为填写主题。



我正在使用输入,type =text标签输入主题,我想象这是原因的一部分。我可以使用textarea标签来解决问题,但这并不是很常见的,并且似乎打败了练习的目的。任何帮助是赞赏。谢谢!



这是我的代码:
(第一个块只是一个生成表单的函数。)

  function createForm()//在页面加载时创建表单
{
echo'< form method =post>'。 '< br />';
echo'< fieldset>'。 '< br />';
echo'< legend>< p>标题< / p>< / legend>'。 '< br />';
echo'To:< input name =totype =text/>'。 '< br />';
echo'From:< input name =fromtype =text/>'。 '< br />';
echo'主题:< input name =subjecttype =text/>'。 '< br />';
echo'< / fieldset>'。 '< br />';
echo'< fieldset>'。 '< br />';
echo'< legend>< p> Content< / p>< / legend>'。 '< br />';
echo'Message:< textarea name =messagecols =30rows =10>< / textarea>'。 '< br />';
echo'< input name =sendtype =submit/>'。 '< br />';
echo'< / fieldset>'。 '< br />';
echo'< / form>';
}

实际发送电子邮件代码:

  if(isset($ _ REQUEST ['to']))//发送电子邮件
{
$ to = $ _REQUEST ['to' ]。
$ subject = $ _REQUEST ['subject'];
$ from = $ _REQUEST ['from'];

$ headers =MIME-Version:1.0。 \r\\\
;
$ headers。='Content-Type:text / html; charset = iso-8859-1'。 \r\\\
;
$ headers。=From:$ from。 \r\\\
;
$ headers。=Reply-To:$ from。 \r\\\
;
$ headers。=主题:$ subject。 \r\\\
;
$ headers。=X-Mailer:PHP /。phpversion()。 \r\\\
;

// html message
$ message ='
< html>
< body>
< form>
< fieldset>
< legend>标题< / legend>
至:< input type =textname =tovalue ='。 $ _REQUEST ['to']。 '/>< br />
From:< input type =textname =fromvalue ='。 $ _REQUEST ['from']。 '/>< br />
主题:< input type =textname =subjectvalue ='。 $ _REQUEST ['subject']。 '/>
< / fieldset>
< fieldset>
< legend>内容< / legend>
消息:< textarea name =messagecols =30rows =10>'。 $ _REQUEST ['message']。 '< / textarea>< br />
< input type =submitname =send/>
< / fieldset>
< / form>
< / body>
< / html>';

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

echo发送消息,谢谢。< br />;
echo'< a href =email.php>返回< / a>';
}
else
{
createForm(); //如果没有$设置,则创建表单。
}


解决方案

邮件中的HTML解释器程序正在查看输入元素,并看到属性,后跟单个未引用的单词。然后它看到一些其他属性没有值。首先报价值正确。和清洁您不希望客户端遭到黑客攻击,因为您的系统发送了一封电子邮件。


I am currently learning php for a web interface class, and one of our assignments is to generate a basic form to send an email with. We then have to be able to send a sample of that form in an email through html. I want to do this showing the the input that was entered when the email was sent. I've got most of it working, I just can't get the $subject variable to completely populate within the sample. It will only show one word, and skip all others after the first space character. (The same is true of the $from variable, however this will typically be an email address and thus its not a major issue)

For example, if I send an email with the subject,"This is a test", when I receive the email in my inbox I will see the full subject "This is a test" in my email's subject line. But when I open the email itself and look at the generated form sample I will only see "This" as the filled in subject.

I am using the input, type="text" tag to enter the subject and I imagine that is part of the reason. I can solve the problem using a textarea tag, but that's not really conventional and seems to defeat the purpose of the exercise. Any help is appreciated. Thanks!

Here is my code: (The first block is just a function to generate the form.)

function createForm() //create form upon page load
{
    echo '<form method="post">' . '<br />';
    echo '<fieldset>' . '<br />';
    echo '<legend><p>Heading</p></legend>' . '<br />';
    echo 'To: <input name="to" type="text" />' . '<br />';
    echo 'From: <input name="from" type="text" />' . '<br />';
    echo 'Subject: <input name="subject" type="text"  />' . '<br />';
    echo '</fieldset>' . '<br />';
    echo '<fieldset>' . '<br />';
    echo '<legend><p>Content</p></legend>' . '<br />';
    echo 'Message: <textarea name="message" cols="30" rows="10"></textarea>' . '<br />';
    echo '<input name="send" type="submit" />' . '<br />';
    echo '</fieldset>' . '<br />';
    echo '</form>';
}

And the actual send email code:

if(isset($_REQUEST['to'])) //send email 
{
    $to = $_REQUEST['to'];
    $subject = $_REQUEST['subject'];
    $from = $_REQUEST['from'];

    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= 'Content-Type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= "From: $from" . "\r\n";
    $headers .= "Reply-To:  $from"  . "\r\n";
    $headers .= "Subject: $subject" . "\r\n";
    $headers .= "X-Mailer: PHP/".phpversion() . "\r\n";

    //html message
    $message = '
    <html>
    <body>
    <form>
    <fieldset>
    <legend>Headings</legend>
    To: <input type="text" name="to" value=' . $_REQUEST['to'] . ' /><br />
    From: <input type="text" name="from" value=' . $_REQUEST['from'] . ' /><br />
    Subject: <input type="text" name="subject" value=' . $_REQUEST['subject'] . ' />
    </fieldset>
    <fieldset>
    <legend>Content</legend>
    Message: <textarea name="message" cols="30" rows="10">' . $_REQUEST['message'] . '</textarea><br />
    <input type="submit" name="send" />
    </fieldset>
    </form>
    </body>
    </html>';   

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

    echo "Message sent, thank you. <br />";
    echo '<a href="email.php">Return</a>';
}
else
{
    createForm(); //create form if no $to set. 
}

解决方案

The HTML interpreter in the mail program is looking at the input elements and seeing the value attribute followed by a single unquoted word. Then it sees a bunch of other attributes without values. Quote the value properly in the first place. And sanitize too; you don't want your clients being hacked because of an email that was sent from your system.

这篇关于$主题以php邮件形式返回字符串中的第一个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆