Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新到PHP7后,邮件脚本停止工作_Php_Email_Php 7 - Fatal编程技术网

更新到PHP7后,邮件脚本停止工作

更新到PHP7后,邮件脚本停止工作,php,email,php-7,Php,Email,Php 7,我有一个mailscript,它在更新到PHP7后停止工作 但我不知道为什么它停止工作,我使用ajax发布到该脚本,所以我没有看到任何PHP错误,只是发布时在我的网络选项卡中出现了500个错误 这是我的剧本: <?php /* ========================== Define variables ========================== */ #Your e-mail address define("__TO__", "test@live.nl"); i

我有一个mailscript,它在更新到PHP7后停止工作

但我不知道为什么它停止工作,我使用ajax发布到该脚本,所以我没有看到任何PHP错误,只是发布时在我的网络选项卡中出现了500个错误

这是我的剧本:

<?php
/* ==========================  Define variables ========================== */

#Your e-mail address
define("__TO__", "test@live.nl");

if ($_POST['contact-form'] == 'true') {
    #Message subject
    define("__SUBJECT__", "Contact aanvraag");
    $productpakket = 'Pakket';
}

if ($_POST['contact-form'] == 'false') {
    #Message subject
    define("__SUBJECT__", "Ketel/Informatie aanvraag");
    $productpakket = 'Product';
}

if ($_POST['offerte'] == 'true') {
    #Message subject
    define("__SUBJECT__", "Offerte aanvraag");
}

#Success message
define('__SUCCESS_MESSAGE__', "Uw bericht is verstuurd, bedankt!");

#Error message
define('__ERROR_MESSAGE__', "Error, uw bericht is niet verstuurd");

#Messege when one or more fields are empty
define('__MESSAGE_EMPTY_FILDS__', "Vult u alstublieft alle velden in");

/* ========================  End Define variables ======================== */

//Send mail function
function send_mail($to, $subject, $message, $headers) {
    if (@mail($to, $subject, $message, $headers)) {
        echo json_encode(array('info' => 'success', 'msg' => __SUCCESS_MESSAGE__));
    } else {
        echo json_encode(array('info' => 'error', 'msg' => __ERROR_MESSAGE__));
    }
}

//Check e-mail validation
function check_email($email) {
    if (!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
        return false;
    } else {
        return true;
    }
}

//Get post data
if (isset($_POST['name']) and isset($_POST['mail']) and isset($_POST['comment'])) {
    $hidden     = $_POST['hidden'];
    $name       = $_POST['name'];
    $mail       = $_POST['mail'];
    $website    = $_POST['website'];
    $comment    = $_POST['comment'];
    $over       = $_POST['over'];
    $adres      = $_POST['adres'];
    $woonplaats = $_POST['woonplaats'];
    $tel        = $_POST['telefoon'];
    $tijd       = $_POST['tijd'];
    $keteltype  = $_POST['ketel'];
    $offertevoor= $_POST['offertevoor'];
    $product    = $_POST['product'];
    $plaatsnaam = $_POST['plaatsnaam'];

    if ($name == '') {
        echo json_encode(array('info' => 'error', 'msg' => "U heeft geen naam ingevuld."));
        exit();
    } else if ($mail == '' or check_email($mail) == false) {
        echo json_encode(array('info' => 'error', 'msg' => "U heeft geen geldig email adres ingevoerd."));
        exit();
    } else if ($comment == '') {
        echo json_encode(array('info' => 'error', 'msg' => "U heeft geen bericht ingevuld."));
        exit();
    } else {
        //Send Mail

        if ($_POST['offerte'] != 'true') {
            if ($hidden == '') {
                $hidden_field = '';
            } else if ($hidden != '') {
                $hidden_field = '<tr style="height: 32px;">
                                  <th align="right" style="width:150px; padding-right:5px;">'.$productpakket.':</th>
                                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$hidden.'</td>
                                </tr>';
            }

            if ($over == '') {
                $over_field = '';
            } else if ($over != '') {
                $over_field = '<tr style="height: 32px;">
                                  <th align="right" style="width:150px; padding-right:5px;">Onderhouds contract:</th>
                                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$over.'</td>
                                </tr>';
            }

            $to      = __TO__;
            $subject = __SUBJECT__.' '.$name;
            $message = '
            <html>
            <head>
              <title>Mail from '.$name.'</title>
            </head>
            <body>
              <table style="width: 500px; font-family: arial; font-size: 14px;" border="1">
              '.$hidden_field.'
              '.$over_field.'
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">Naam:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$name.'</td>
                </tr>
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">E-mail:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$mail.'</td>
                </tr>
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">Telefoonnummer:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$website.'</td>
                </tr>
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">Plaatsnaam:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$plaatsnaam.'</td>
                </tr>
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">Bericht:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$comment.'</td>
                </tr>
              </table>
            </body>
            </html>
            ';
        } else {
            if ($hidden == '') {
                $hidden_field = '';
            } else if ($hidden != '') {
                $hidden_field = '<tr style="height: 32px;">
                                  <th align="right" style="width:150px; padding-right:5px;">Offerte voor:</th>
                                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$offertevoor.'</td>
                                </tr>';
            }

            if ($over == '') {
                $over_field = '';
            } else if ($over != '') {
                $over_field = '<tr style="height: 32px;">
                                  <th align="right" style="width:150px; padding-right:5px;">Onderhouds contract:</th>
                                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$over.'</td>
                                </tr>';
            }

            $to      = __TO__;
            $subject = __SUBJECT__.' '.$name;
            $message = '
            <html>
            <head>
              <title>Mail from '.$name.'</title>
            </head>
            <body>
              <table style="width: 500px; font-family: arial; font-size: 14px;" border="1">
              '.$hidden_field.'
              '.$over_field.'
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">Naam:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$name.'</td>
                </tr>
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">Adres:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$adres.'</td>
                </tr>
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">Woonplaats:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$woonplaats.'</td>
                </tr>
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">Telefoon:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$telefoon.'</td>
                </tr>
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">E-mail:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$mail.'</td>
                </tr>
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">Tijdsspan:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$tijd.'</td>
                </tr>
                <tr style="height: 32px;">
                  <th align="right" style="width:150px; padding-right:5px;">Ketel:</th>
                  <td align="left" style="padding-left:5px; line-height: 20px;">'.$keteltype.'</td>
                </tr>
              </table>
            </body>
            </html>
            ';
        }

        $headers = 'MIME-Version: 1.0'."\r\n";
        $headers .= 'Content-type: text/html; charset=utf-8'."\r\n";
        $headers .= 'From: '.$mail."\r\n";

        if (send_mail($to, $subject, $message, $headers)) {
            echo json_encode(array('success' => 'error', 'msg' => 'Bedankt voor het opnemen van contact'));
        }
    }
} else {
    echo json_encode(array('info' => 'error', 'msg' => __MESSAGE_EMPTY_FILDS__));
}
?>

将错误报告设置为显示所有错误,并直接转到我的浏览器中的php文件,也不会显示任何内容

如何修复它?

问题(或至少是第一个问题?)位于
检查邮件功能的第一行代码中

if (!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
eregi()
函数已被弃用,并从PHP7.0开始删除。您需要将其替换为
preg\u match()
或类似内容

它没有显示错误消息的原因是您使用了
@
前缀,它告诉PHP抑制错误。正是由于这种原因,现在使用
@
操作符被认为是不好的做法


可能还有其他问题;我还没有机会进一步阅读代码,但这段代码立即跳了出来。

你可以在那里下载fiddler,你可以看到php请求已完成,并看到错误消息。检查可能需要安装sendmail或Postfix。你不能再使用多行标题了。这些信息必须放在正文中。友好的建议:扔掉所有这些代码,替换为PHPMailer或SwiftMailer库。当然,查看错误日志应该会使明显的
ereri
问题变得明显