0

I have used a PHP mailer for a long time. Now I have figured out that the mailer isn't working anymore on my website. Here is the code and I want to ask you what could be wrong ?

<?php

error_reporting(E_ALL ^ E_NOTICE); 

if(isset($_POST['submitted'])) {
    if(trim($_POST['contactName']) === '') {
        $nameError =  'Sie haben ihren Namen vergessen.'; 
        $hasError = true;

    } else {
        $name = trim($_POST['contactName']);
    }

    if(trim($_POST['betreff']) === '') {
        $betrError = 'Sie haben ihr Betreff - Anliegen vergessen.'; 
        $hasError = true;
    } else {
        $betreff = trim($_POST['betreff']);
    }

    $telefon = trim($_POST['telefon']);
    $company = trim($_POST['company']);
    if(trim($_POST['email']) === '')  
    {
        $emailError = 'Sie haben ihre Email Adresse vergessen.';
        $hasError = true;

    } else if
    (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i",trim($_POST['email']))) 
    {

        $emailError = 'Sie haben ihre Email Adresse falsch eingegeben.';
        $hasError = true;

    } else {

        $email = trim($_POST['email']);
    }

    if(trim($_POST['comments']) === '') {
        $commentError = 'Sie haben ihre Nachricht vergessen.';
        $hasError = true;

    } else {

        if(function_exists('stripslashes')) {

            $comments = utf8_encode(stripslashes(trim($_POST['comments'])));

        } else {

            $comments = trim($_POST['comments']);

        }

    }


    if(!isset($hasError)) {

        $emailTo = 'example@example.de';
        $subject = 'example.de - '.$name.' - '.$betreff;
        $sendCopy = trim($_POST['sendCopy']);
        $body = "\n\nDies ist eine Email von ihrem Kontakt Formular auf der Webseite http://www.example.de/\nAlle uebermittelten Daten des Benutzers durch das Formular finden sie unterhalb dieses Textes.\n\nFirma - Unternehmen : $company\n\nName - Ansprechpartner : $name \n\nEmail-Adresse : $email \n\nTelefon-Nr. : $telefon \n\nBetreff - Anliegen : $betreff\n\nNachricht des Nutzers: $comments\n\n";
        $headers = "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n";

        mail($emailTo, $subject, $body, $headers);

        $emailSent = true;

    }
}

?>

And here is the Javascript for the success or error message. If I send the mail with the form it says the email was sent. But at the end I have no incoming message in my inbox and or spam.

<script type="text/javascript">
<!--//--><![CDATA[//><!--
$(document).ready(function() {
    $('form#contact-us').submit(function() {
        $('form#contact-us .error').remove();
        var hasError = false;
        $('.requiredField').each(function() {
            if($.trim($(this).val()) == '') {
                var labelText = $(this).prev('label').text();
                $(this).parent().append('<br><br>Sie haben ihre '+labelText+'.     vergessen.');
                $(this).addClass('inputError');
                hasError = true;
            } else if($(this).hasClass('email')) {
                var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
                if(!emailReg.test($.trim($(this).val()))) {
                    var labelText = $(this).prev('label').text();
                    $(this).parent().append('<br><br>Sie haben eine Falsche '+labelText+' Adresse angegeben.');
                    $(this).addClass('inputError');
                    hasError = true;
                }
            }
        });
        if(!hasError) {
            var formInput = $(this).serialize();
            $.post($(this).attr('action'),formInput, function(data){
                $('form#contact-us').slideUp("fast", function() {
                    $(this).before('<br><br><strong>Danke !</strong>Ihre Email wurde erfolgreich Übermittelt.');
                });
            });
        }
        return false;
    });
});
//-->!]]>
</script>

Here now the HTML 5 output. If I fill out the form and send the mail it says that the mail went trough and everything went right. But for some reason I don't get any mail in my inbox and or spam. Feel free to try it out by yourself. Maybe I am just having a lil braindead issue.

Nisse Engström
  • 4,636
  • 22
  • 26
  • 40
HumanCK
  • 1
  • 3
  • 1
    `if(mail($emailTo, $subject, $body, $headers)){ echo "Mail has done its job and is out of your hands. Check your spam."; } else { echo "Something went wrong, and you need to find out why."; }` – Funk Forty Niner Mar 13 '16 at 20:37
  • that email validation is past its due date, many legit addresses will fail it –  Mar 13 '16 at 20:41
  • Hey Dagon, just want to make sure that i understand this right. The script i used is now oldschool and not up to date with technics ? – HumanCK Mar 14 '16 at 08:21

0 Answers0