【问题标题】:TextArea line breaks for e-mail电子邮件的 TextArea 换行符
【发布时间】:2011-05-01 07:31:09
【问题描述】:

如何从 textarea (html) 中获取文本并插入换行符。现在,如果我输入要作为电子邮件发送的信息,它会将所有文本放在同一行,没有任何换行符。

使用 $_POST['field'] 从表单中获取数据并使用 PHP 邮件发送。

【问题讨论】:

    标签: php html phpmailer


    【解决方案1】:

    使用nl2br() 函数。它将字符串中的所有换行符替换为 html br 标签。

    【讨论】:

      【解决方案2】:

      使用 \n 换行,或 \r\n 换行后回车

      即。

      <?php
      printf("This is the first line. \n");
      printf("This is the second line");
      ?>
      

      即。用换行符替换
      html 标记:

      str_replace ('<br>' , '\r\n', $_POST['field'])
      

      或者将您发送的电子邮件设置为 html 编码(添加 html 标头)

      【讨论】:

        【解决方案3】:

        在 php 中,将 \n 替换为 html 的 br 标签,

        $newTxt = str_replace("\n",'<br>',$txt) 
        

        nl2br() 将达到您的目的。

        【讨论】:

          【解决方案4】:

          删除stripslashes(),这样就可以了。

          【讨论】:

          • stripslashes 删除 \n\r 的任何实例,但实际上并未按照 OP 的要求在字符串中插入足够的换行符。
          猜你喜欢
          • 2013-01-19
          • 2012-04-02
          • 1970-01-01
          • 2013-11-14
          • 2011-03-13
          • 1970-01-01
          • 2010-10-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多