0

All,

I've got this problem where the mail is being send and I get a notification is has been but the mail is not coming inside my email software. Also can't find in any unwanted or spam folders... I've checked this.

This php file is being called by a html form.

Any tips would be welcome! Thanks in advance!

<?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;
}
?>
Rotimi
  • 4,783
  • 4
  • 18
  • 27
TDB
  • 19
  • 4
  • 1
    You have the symbol @ before the mail command. Remove the @ symbol. Mail function will return a value so check if false is returned if it fails. – Andrew Schultz Mar 27 '18 at 11:27
  • Change `@mail()` to `mail()` to NOT surpress errors/warnings. https://secure.php.net/manual/en/language.operators.errorcontrol.php – brombeer Mar 27 '18 at 11:28

0 Answers0