为什么 \n 在我的 PHP 脚本的某一行上不起作用,但在其他所有行上都正常?
我正在写一封电子邮件,在提交表格时发送。由于某种原因,\n
字符在除一行之外的所有行上正确显示。我看不出这条线和其他线有什么区别,所以无法弄清楚为什么它不起作用。下面的代码以及我得到的输出以及所使用的变量列表。
正如您从电子邮件中看到的,“工作地址”行末尾的 \n
不起作用,因此“公司名称”只是直接跟在后面,而不是在下一行。然后公司名称后面的 \n
就可以正常工作,因此家庭地址位于下一行。
这是消息的代码:
$xmsg = "First Name: $firstname\n" .
"Last Name: $lastname\n" .
"Work Tel: $worktel\n" .
"Home Tel: $hometel\n" .
"Mobile Tel: $mobtel\n" .
"E-mail: $email\n" .
"Work Address: $workad\n" .
"Company Name: $company\n" .
"Home Address: $homead\n" .
这是输出:
First Name: Joe
Last Name: Bloggs
Work Tel: 0123456789
Home Tel: 0987654321
Mobile Tel: 0789456123
E-mail: [email protected]
Work Address: Bloggoffice, Joe Street, London, N1 J0E Company Name:
Home Address: 9 Blogg Street, Borough of Joe, London, SE4 J03
如果它有用,这里是使用的变量列表:
$firstname = $_SESSION['firstname'];
$lastname = $_SESSION['lastname'];
$worktel = $_SESSION['worktel'];
$hometel = $_SESSION['privtel'];
$mobtel = $_SESSION['mobtel'];
$email = $_SESSION['email'];
$company = $_SESSION['companyname'];
$workad = $_SESSION['workad1'] . ', ' . $_SESSION['workad2'] . ', ' . $_SESSION['workad3'] . ', ' . $_SESSION['workpostcode'];
$homead = $_SESSION['homead1'] . ', ' . $_SESSION['homead2'] . ', ' . $_SESSION['homead3'] . ', ' . $_SESSION['homepostcode'];
我将不胜感激寻求任何帮助,我希望这不仅仅是我忽略的一个愚蠢的错误!
I'm writing an e-mail message to be sent on submission of a form. For some reason, the \n
character displays correctly on all lines but one. I can't see any difference between this line and the others, so can't work out why it isn't working. The code is below, together with the output that I'm getting as well as a list of the variables used.
As you can see from the email, the \n
on the end of the 'Work Address' line is not working, so "Company Name" just follows straight on, rather than being on the next line. Then the \n
after company name works fine, so home address is on the next line.
Here's the code for the message:
$xmsg = "First Name: $firstname\n" .
"Last Name: $lastname\n" .
"Work Tel: $worktel\n" .
"Home Tel: $hometel\n" .
"Mobile Tel: $mobtel\n" .
"E-mail: $email\n" .
"Work Address: $workad\n" .
"Company Name: $company\n" .
"Home Address: $homead\n" .
Here's the output:
First Name: Joe
Last Name: Bloggs
Work Tel: 0123456789
Home Tel: 0987654321
Mobile Tel: 0789456123
E-mail: [email protected]
Work Address: Bloggoffice, Joe Street, London, N1 J0E Company Name:
Home Address: 9 Blogg Street, Borough of Joe, London, SE4 J03
And in case it's useful, here's the list of variables used:
$firstname = $_SESSION['firstname'];
$lastname = $_SESSION['lastname'];
$worktel = $_SESSION['worktel'];
$hometel = $_SESSION['privtel'];
$mobtel = $_SESSION['mobtel'];
$email = $_SESSION['email'];
$company = $_SESSION['companyname'];
$workad = $_SESSION['workad1'] . ', ' . $_SESSION['workad2'] . ', ' . $_SESSION['workad3'] . ', ' . $_SESSION['workpostcode'];
$homead = $_SESSION['homead1'] . ', ' . $_SESSION['homead2'] . ', ' . $_SESSION['homead3'] . ', ' . $_SESSION['homepostcode'];
I'd be grateful for any help, I hope it's not just a stupid mistake that I've overlooked!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
PHP_EOL
常量似乎比使用\n
更正确。因为PHP_EOL
是每个平台的正确行尾字符。Using
PHP_EOL
constant seems more correct than using\n
. BecausePHP_EOL
is the correct end of line character for every platform.