Tyl*_*aft 0 php email if-statement
// from the form
$name = trim(strip_tags($_POST['name']));
$email = trim(strip_tags($_POST['email']));
$message = htmlentities($_POST['message']);
// set here
$subject = "Contact form submitted!";
$to = 'your@email.com';
$body = HTML
$message
HTML;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
// send the email
mail($to, $subject, $body, $headers);
// redirect afterwords, if needed
header('Location: thanks.html');
Run Code Online (Sandbox Code Playgroud)
问题是,天气与否,你可以在html电子邮件正文中插入php if语句或在其中添加它的最佳方式.我正在创建详细的广告资源,一旦提交,就需要通过电子邮件发送到电子邮件.但我不想通过电子邮件发送完整的库存(包括空输入),它应该只通过电子邮件发送除了0之外的字段.我在想:
if ($armChair > 0) { echo 'Arm Chairs: ' . $_POST['armChair']; } ]
但它似乎没有实际工作...任何想法?
这是一个构造错误的问题.
是的,你绝对可以做到,但你需要以一种理智的方式做到这一点.我们无法确定您在此处发布的内容,因为您只需插入定义正文的"HTML".
$body = "Hi there,\r\n";
$body .= $armChair > 0 ? "Arm Chairs: ".$_POST['armCharis']."\r\n" : "";
$body.= "some more text";
Run Code Online (Sandbox Code Playgroud)
如果你的意思是覆盖$ message的一部分,是的,你也可以使用机器标签{INVENTORY}之类的东西......
$message = $armChair > 0 ? str_replace('{INVENTORY}', "Arm Chairs: ".$_POST['armCharis']."\r\n", $message) : "";
Run Code Online (Sandbox Code Playgroud)
这当然需要$ message var中某处的字符串{INVENTORY}
| 归档时间: |
|
| 查看次数: |
1320 次 |
| 最近记录: |