php - 使 phpmailer 不使用 if 语句回显空输入
问题描述
我有一个带有输入的表单,如果客户不知道某些内容,他将字段留空并提交表单,然后发送一封电子邮件,他们可以根据表单获得相当长的时间。所以 IM 试图做到这一点,所以当输入为空时,它不会在 phpmailer 中回显它。但是,我不确定该怎么做,所以这就是我想出的。我究竟做错了什么?
// defines how message looks in email
$mail->Body="
<html>
<head>
</head>
<body>
<center>
<span style='color:red;'>This customer needs a repair quote. Lets not keep him waiting!</span>
<div style='width:750px;text-align:center;'>
<div style='float:;'>
<span style='font-size:px;'><b>Personal Info</b><br></span>
<br>
<span style='font-size:px;'>---------------<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Full Name: </span>$name<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Phone Number:</span> $phone<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Email:</span> $email<br></span>
</div>
<br>
<div style='float:;'>
<span style='font-size:px;'><b>Vehicle Info</b><br></span>
<br>
<span style='font-size:px;'>---------------<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Vehicle make:</span> $make<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Vehicle Model:</span> $model<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Year:</span> $year<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Vin:</span> $vin<br></span>
if (empty($_POST[$message])) {
// Evaluates post if empty moves on. If somone puts text in in echos it out
// do nothing or move to next line of code
echo '';
} else {
echo '<br><span style='font-size:px;color:red;'>message:</span>$message<br></span>';
</div>
</div>
</center>
</body>
</html>
";
解决方案
尝试这个:
<?php
$tbody = "
<html>
<head>
</head>
<body>
<center>
<span style='color:red;'>This customer needs a repair quote. Lets not keep him waiting!</span>
<div style='width:750px;text-align:center;'>
<div style='float:;'>
<span style='font-size:px;'><b>Personal Info</b><br></span>
<br>
<span style='font-size:px;'>---------------<br></span>
<br>";
if (!empty($_POST["name"])) {
$tbody .= "
<span style='font-size:px;'><span style='font-size:px;color:red;'>Full Name: </span>$name<br></span>
<br>
";
}
if (!empty($_POST["phone"])) {
$tbody .= "
<span style='font-size:px;'><span style='font-size:px;color:red;'>Phone Number:</span> $phone<br></span>
<br>";
}
if (!empty($_POST["email"])) {
$tbody .= "
<span style='font-size:px;'><span style='font-size:px;color:red;'>Email:</span> $email<br></span>
";
}
$tbody .= "</div>
<br>
<div style='float:;'>
<span style='font-size:px;'><b>Vehicle Info</b><br></span>
<br>
<span style='font-size:px;'>---------------<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Vehicle make:</span> $make<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Vehicle Model:</span> $model<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Year:</span> $year<br></span>
<br>
<span style='font-size:px;'><span style='font-size:px;color:red;'>Vin:</span> $vin<br></span>
</div>
</div>
</center>
</body>
</html>
";
$mail->Body = $tbody;
?>
- 我只对三个参数添加了检查,但您可以随心所欲地进行检查。
.=
标志手段add the next string to the previous string
推荐阅读
- ruby-on-rails - # 的未定义方法
我有这个内部
User
模型def self.home_opinions (user) home_opinions = user.opinions user.follows.find_each do |follow| home_opinions+=(follow.opinions) end
- spring - 将 MapsId 与非主键的引用列一起使用
- iphone - 如何测试 Apple 用户的多次登录?
- reactjs - 在第一次渲染时对 localStorage 空数组和 null 做出反应
- java - 如何使标记在 Java 中遍历折线?
- google-apps-script - 错误 .getValues () is not a function Google Apps Script
- python - github上的混淆python代码,我怀疑是恶意代码
- numpy - 仅使用 Numpy 从头开始实现自我注意。如何处理具有 3-D 输入的批量数据?
- python - 有没有办法将此循环缩短为一行?
- flutter - 如何为 QuerySnapshot 提供初始数据