gpt4 book ai didi

php - 为什么通过 php 发送的电子邮件中的文本被换行?

转载 作者:行者123 更新时间:2023-12-04 16:44:47 24 4
gpt4 key购买 nike

我正在为我网站的客户编写一个用于确认订单的电子邮件脚本。我遇到了一个问题,即电子邮件中显示的订单总数被放置在一个新行中,但是代码中没有新行。我附上了正在发生的事情的图像。 enter image description here

这是我的代码:

<?php
if(isset($_POST['email']) && isset($_POST['name']) && isset($_POST['order'])) {
$to = $_POST['email'];
$name = $_POST['name'] .",";
$order = $_POST['order'];
$trackingNumber = $_POST['trackingNumber'];
$totalAmount = "Your total was: $".$_POST['totalAmount'];

if(!empty($to) && !empty($name) && !empty($order)) {

$subject = 'From the band.it team ';
$text = "My name is Bobby and I am a part of band.it's fulfillment Team! We recieved your order and are working to process it from our Gainesville, Florida facility. Feel free to reach out to us at any point with any comments, questions, or concerns. You can find our contact infomation at the bottom of this email.";
$body = "Hey ".$name."\r\n".$text."\r\nYour order will contain:\r\n".$order."\r\n";
$body = $body.$totalAmount;
$body = $body."\r\nYou can track your package through USPS with this number:\r\n".$trackingNumber."\r\n";
$body = $body."\r\nYou can view any order you've made with us via going to the following link with your tracking number handy!\r\nhttps://camerabandit.com/findAnOrder/";
$body = $body."\r\n\r\nThanks again for your support of the band.it team, and reach out to us anytime by sending an email to contact@camerabandit.com";
$headers = 'Order Confirmed';

if (mail($to, $subject, $body, $headers)) {
echo 'Mail has been sent';
} else {
echo 'Mail failed to send';
}
}
}
?>

最佳答案

我最好的猜测是 $_POST['totalAmount'] 包含换行符。
您可能想要 trim()它:

$totalAmount = "Your total was: $".trim($_POST['totalAmount']);

关于php - 为什么通过 php 发送的电子邮件中的文本被换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43727702/

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