我有一个带有联系表单的网站,当我提交详细信息时,我收到有关已弃用eregi()
的错误消息。这是似乎有问题的代码块。我不知道php,所以有人可以伸手吗?
if (email_is_valid($youremail) && !eregi("\r",$youremail) && !eregi("\n",$youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {
mail($to,$subject,$message,$headers);
$yourname = '';
$youremail = '';
$yourmessage = '';
echo '<p style="color: #200041; text-align: center;">'.$contact_submitted.'</p>';
}
答案 0 :(得分:2)
不推荐使用Eregi,因此请将其从代码中删除:
if (email_is_valid($youremail)&& $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {
mail($to,$subject,$message,$headers);
$yourname = '';
$youremail = '';
$yourmessage = '';
echo ''.$contact_submitted.'
你可以忘掉它,因为它只检查新的线路标志 如果你想保持新的行检查,用preg_match函数替换eregi(但请阅读有关它的手册)。
答案 1 :(得分:1)
eregi()
已弃用。所以你可以使用preg_match()
您的代码将是
<?php
if (email_is_valid($youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) == '$answer')
{
mail($to,$subject,$message,$headers);
$yourname = '';
$youremail = '';
$yourmessage = '';
echo '<p style="color: #200041; text-align: center;">'.$contact_submitted.'</p>';
}
else
{
echo '<p style="color: red; text-align: center;">Error</p>';
}