猿问

如果变量为空,则不要在电子邮件中包含表格 - PHP

我有 html 表单并通过 php 处理以发送电子邮件。如果变量 ($ans01) 为空,如何隐藏表格而不包含在电子邮件中?


$message    .= '<table width="100%" rules="rows" style="border: 1px solid #0066cc;" cellpadding="5">';

$message    .= "<tr><td colspan='2'>This line is question and answer is below?</td></tr>";

$message    .= "<tr><td colspan='2' style='color:#0000FF;'><strong>" .$ans01. "</strong></td></tr>";

$message    .= "</table><br>";


UYOU
浏览 138回答 1
1回答

牧羊人nacy

只需添加 if with empty($ans01) 等于 not。代码:if (!empty($ans01)) {&nbsp; &nbsp; $message&nbsp; &nbsp; .= '<table width="100%" rules="rows" style="border: 1px solid #0066cc;" cellpadding="5">';&nbsp; &nbsp; $message&nbsp; &nbsp; .= "<tr><td colspan='2'>This line is question and answer is below?</td></tr>";&nbsp; &nbsp; $message&nbsp; &nbsp; .= "<tr><td colspan='2' style='color:#0000FF;'><strong>" .$ans01. "</strong></td></tr>";&nbsp; &nbsp; $message&nbsp; &nbsp; .= "</table><br>";}
随时随地看视频慕课网APP
我要回答