我是 PHP 新手。这是我的 mailing.php 中的代码。当用户提交请求时,有 5-7 个可选字段和 20-25 个字段最终未被选择。输出列出所有字段和值,无论它们是空的还是已被选择。我知道我需要使用unset
or array_filter
,但无法弄清楚我需要如何以及在何处插入代码。
if($_POST && count($_POST)) {
$body = '';
foreach($_POST as $key=>$value)
$body .= $key . ": " . $value . "\r\n";
mail("[email protected] /cdn-cgi/l/email-protection", "Email Received at [email protected] /cdn-cgi/l/email-protection", $body);
你可以试试这个
if($_POST && count($_POST)) {
$_POST = array_filter($_POST);
$body = '';
foreach($_POST as $key=>$value)
$body .= $key . ": " . $value . "\r\n";
mail("[email protected] /cdn-cgi/l/email-protection", "Email Received at [email protected] /cdn-cgi/l/email-protection", $body);
OR
if($_POST && count($_POST)) {
$body = '';
foreach($_POST as $key=>$value){
$trim_value = trim($value);
if (!empty($trim_value)){
$body .= $key . ": " . $value . "\r\n";
}
}
mail("[email protected] /cdn-cgi/l/email-protection", "Email Received at [email protected] /cdn-cgi/l/email-protection", $body);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)