PHP联系表单提交

时间:2016-06-07 23:41:05

标签: php forms email

我遇到了“str_replace”并认为我可以使用它来消除下划线。 我已经尝试了十几次,但我无法让它发挥作用。你能告诉我我做错了吗?

在电子邮件中使用下划线输出

Mortgage_Company :
XYZ Comp
Mcstreet :
77 Main Road

页面表格

<h1>Mortgage Company Information</h1>
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
    <label for='Mortgage_Company'>Company Name* </label>
    <input type='text' name='Mortgage_Company' id='Mortgage_Company' value='<?php echo $formproc->SafeDisplay('Mortgage_Company') ?>' maxlength="50" /><br/>
    <span id='contactus_Mortgage_Company_errorloc' class='error'></span>
</div>
<div class='container'>
    <label for='mcstreet' >Company Street Address* </label>
    <input type='text' name='mcstreet' id='mcstreet' value='<?php echo $formproc->SafeDisplay('mcstreet') ?>' maxlength="50" /><br/>
    <span id='contactus_mcstreet_errorloc' class='error'></span>
</div>

数组的部分

$ret_str='';
        foreach($_POST as $key=>$value)
        {
            if(!$this->IsInternalVariable($key))
            {
                $value = htmlentities($value,ENT_QUOTES,"UTF-8");
                $value = nl2br($value);
                $key = ucfirst($key);
                // str_replace
                $key = str_replace("_"," ",$key);
                $ret_str .= "<div class='label'>$key :</div><div class='value'>$value </div>\n";

            }
        }

1 个答案:

答案 0 :(得分:1)

为了在字符串中使用变量和\ n,您需要使用双引号,例如:

$retstr ="Here are the details:\n Name: $name \n Association: $association \n Street: $street \n E-mail: $email";

以这种方式试试。