PHP表单停止从提交中发送电子邮件

时间:2017-01-19 21:42:16

标签: php forms function email undefined

我在第4行遇到问题。每个人提交的时间和电子邮件都是虚假条目,我收到此错误

  

致命错误:未捕获错误:在/homepages/29/d409157025/htdocs/contacts.php:31中调用未定义函数eregi()堆栈跟踪:#home {29} / dp9157025 / htdocs /#0 {main}第4行的contacts.php

自上传以来,该表格完美无缺,已经过了一年多。

//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '')  {
    $hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
    $hasError = true;
} else {
    $email = trim($_POST['email']);
}

//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
    $hasError = true;
} else {
    if(function_exists('stripslashes')) {
        $comments = stripslashes(trim($_POST['message']));
    } else {
        $comments = trim($_POST['message']);
    }
}

//If there is no error, send the email
if(!isset($hasError)) {
    $emailTo = 'info@roswellhistoriccottage.com, artem.alek@icloud.com'; //Put your own email address here
    $body = "Name: $name \n\nEmail: $email \n\nComments:\n $comments";
    $headers = 'From: RHC Website Information Request <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

    mail($emailTo, $subject, $body, $headers);
    $emailSent = true;
}

1 个答案:

答案 0 :(得分:1)

{@ 3}}函数已弃用,已在PHP 7中删除。您或您的主机最近将您更新为PHP 7。

要解决此问题,您需要更改代码以改为使用eregi()