gpt4 book ai didi

PHP-表单邮件插入!并换行成长字符串

转载 作者:可可西里 更新时间:2023-11-01 13:15:14 25 4
gpt4 key购买 nike

我公司网站上有一个表格,其中包含姓名、电话号码和评论(以及其他一些内容)。评论框允许您输入最多 5000 个字符 - 对于非常冗长的客户来说,这是一个很大的限制。有效表格的内容使用 php 表格邮件作为纯文本电子邮件发送给我们的销售部门。

出于某种原因,如果评论超过 1000 个字符,它们将带有感叹号、换行符,有时还会插入缩进。请注意,这仅适用于电子邮件;如果表单有错误,数据会被插入到表单中并标记错误,并且注释还没有感叹号+换行符。

我发现一篇关于它的论坛帖子暗示存在大约 990 个字符的字符限制导致了这个问题。

有人知道原因吗?有谁知道一个相当简单的解决方法?

相关PHP代码:

$to = $email;

$subject = "Website Order Received: $offer";

$contents = "
Order Form Received -\n
Name: $name\n
Company: $company\n
Email: $email\n
Phone: $phone $phoneExt\n
Order Contents:\n" .
($offer == 'web-demo' ? "- I want a live software demonstration.\n" : "") .
($offer == 'pricing' ? "- I'd like pricing information.\n" : "") .
($offer == 'holiday-pricing' ? "- I'd like to sign up before December 31st for the special holiday offer!\n" : "") .
($offer == 'bid-help' ? "- Please give me marketing materials and other assistance for winning bids.\n" : "") .
($offer == 'demo-cd' ? "- Send me the full-version demonstration CD.\n" : "");
if (!empty ($comments)) {
$comments = str_replace("
", "\n", $comments); // Preserves line breaks in the comments.
$contents = $contents."\nComments: $comments\n\n";
}
$contents = str_replace("\n", "\r\n", $contents);

mail($to, $subject, $contents);

最佳答案

电子邮件的一行中的字符数有限制:

There are two limits that this standard places on the number of characters in a line. Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF. (RFC 2882)

您可以使用 PHP 函数 wordwrap实现这一目标:

$contents = wordwrap($contents);

无论如何,这将提高随脚本发送的电子邮件的可读性,并使它们符合标准。

关于PHP-表单邮件插入!并换行成长字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8795259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com