联系表格不接收电子邮件

时间:2018-03-27 11:22:57

标签: php html email contact-form

所有

我在发送邮件的地方遇到了这个问题,我收到通知但是邮件没有进入我的电子邮件软件。也无法在任何不需要的或垃圾邮件文件夹中找到...我已经检查了这个。

这个php文件是由html表单调用的。

欢迎任何提示! 提前谢谢!

<?php

$the_blogname = 'test';
$the_myemail = '...'; //left blank on purpose for this

if (isset($_POST['email'])) {
    error_reporting(0);
    $errorC = false;

    $the_email = $_POST['email'];
    $the_name = $_POST['name'];
    $last_name = $_POST['last-name'];
    $phone = $_POST['phone'];
    $the_message = $_POST['message'];

    $already_used = array(
        'email',
        'name',
        'last-name',
        'phone',
        'message',
        'myblogname',
        'tempcode',
        'temp_url',
        'ajax'
    );
    $attach = '';

    foreach ($_POST as $key => $field) {
        if (!in_array($key, $already_used)) {
            $attach .= $key . ": " . $field . "<br /> \n";
        }
    }
    $attach .= "<br /> \n";

    if (!checkmymail($the_email)) {
        $errorC = true;
        $the_emailclass = "error";
        echo 'Your email is not valid';
    } else {
        $the_emailclass = "valid";
    }

    if ($the_message == "") {
        $errorC = true;
        $the_messageclass = "error";
    } else {
        $the_messageclass = "valid";
    }

    if ($errorC == false) {
        $to = $the_myemail;
        $subject = "Nieuw bericht via site " . $the_blogname;
        $header = 'MIME-Version: 1.0' . "\r\n";
        $header .= 'Content-type: text/html; charset=utf-8' . "\r\n";
        $header .= 'From:' . $the_email . " \r\n";

        $message1 = nl2br($the_message);

        if (!empty($the_name)) {
            $the_name = "Voornaam:      $the_name <br/>";
        }
        if (!empty($last_name)) {
            $last_name = "Achternaam: $last_name <br/>";
        }
        if (!empty($the_phone)) {
            $the_phone = "Telefoonnummer:   $the_phone <br/>";
        }

        $message = "
                Een nieuw bericht via de website <br/>
                $the_name
                $last_name
                $the_phone
                $the_email

                $attach <br />

                Bericht: $the_message <br />";


        if (@mail($to, $subject, $message, $header)) {
            $send = true;
        } else {
            $send = false;
        }

        if (isset($send)) {

            if ($send) {
                echo '<h3>Uw bericht werd verzonden!</h3><div class="confirm">
                        <p class="textconfirm">Wij antwoorden zo spoedig mogelijk.</p>
                      </div>';
            } else {
                echo '<h3>Oops!</h3><div class="confirm">
                        <p class="texterror">Onbekende fout.                      </div>';
            }
        }
    }
}

function checkmymail($mailadresse) {
    $email_flag = preg_match("!^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$!", $mailadresse);

    return $email_flag;
}
?>

0 个答案:

没有答案