1

I got a mailscript which sends the mail (since $mail->send() returns true) and I also got headers which are all looking fine. No error is being shown so I am assuming everything is working, but somehow my mail never arrives anywhere. Not on gmail and not on outlook. What could be the issue? I have sent some test mails from another domain on the same server which works fine.

The domain I am sending from is brand new so I doubt it is blacklisted or something similair.

My html form:

<form id="contact-form" class="contact-form" method="post" action="mail/mail_send.php" role="form">
    <div class="error-container"></div>
    <input type="text" placeholder="Naam *" class="name form-control-name" name="name" required>
    <input type="email" placeholder="E-mail *" class="email form-control-email" name="email" required>
    <input style="width:100%;" type="text" placeholder="Telefoonnummer" class="phone form-control-phone" name="phone">
    <textarea name="message" placeholder="Bericht *" class="message form-control-message" rows="8" cols="20" required></textarea>
    <input type="submit" name="submit" value="Verzenden">
</form>

My ajax script:

$('#contact-form').submit(function(){

     var $form = $(this),
     $error = $form.find('.error-container'),
     action  = $form.attr('action');

     $error.slideUp(750, function() {
     $error.hide();

      var $name = $form.find('.form-control-name'),
        $email = $form.find('.form-control-email'),
        $phone = $form.find('.form-control-phone'),
        $message = $form.find('.form-control-message');

     $.post(action, {
             name: $name.val(),
             email: $email.val(),
             phone: $phone.val(),
             message: $message.val()
        },
        function(data){
             $error.html(data);
             $error.slideDown('slow');

             if (data.match('success') != null) {
                $name.val('');
                $email.val('');
                $phone.val('');
                $message.val('');
             }
        }
     );
});

My PHP mail script:

<?PHP
require_once("../phpMailer/class.phpmailer.php");
$isValid = true;
if(isset($_POST['name']) && isset($_POST['mail']) && isset($_POST['phone']) && isset($_POST['message']))
{
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];
    $subject = 'Er is een aanvraag op de website van website\'s Hairdesign';
    $mail = new PHPMailer;
    $mail->From = $email;
    $mail->FromName = $name;
    $mail->addAddress("my-email@outlook.com");
    $mail->isHTML(true);
    $mail->Subject = $subject;
    $texts = 'Er is een aanvraag op de website van website\'s Hairdesign<br /> <br />
    <b>Naam:</b> '.$name.'<br />
    <b>E-mail adres:</b> '.$email.'<br />
    <b>Telefoonnummer:</b> '.$phone.'<br />
    <b>Bericht:</b> '.$message.'<br /><br /><br />
    ';

    $handtekening = '
    <table border="0" width="100%" cellspacing="0" cellpadding="0" style="font-family:calibri;color: #5C5C5C; font-size:10pt;line-height:22px;">
    <tr>
    <td width="160" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;">
    [contents]
    </td>
    </tr>
    <tr>
    <td width="160" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;">
    Helpdesk<br>
    <b>website\'s Hairdesign</b><br>
    <p></p>
    </td>
    </tr>
    </table>
    <table height="120" border="0" width="100%" cellspacing="0" cellpadding="0" style="font-family:calibri;color: #5C5C5C; font-size:10pt;line-height:22px;">
    <tr>
    <td width="250" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;border-top: 1px #000000 dotted; border-bottom: 1px #000000 dotted;">
    E:&nbsp;&nbsp;
    <a href="mailto:info@websiteshairdesign.nl" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;">info@websiteshairdesign.nl</a><br>
    T:&nbsp;&nbsp;
    <a href="tel:+310181506451" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;">+31-(0)181-506451</a><br>
    W:&nbsp;
    <a href="http://websiteshairdesign.nl/" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;" target="_blank">www.podlogistics.nl</a><br>
    </td>
    <td align="right" style="font-family:calibri;padding-right:10px;padding-top:5px;border-top: 1px #000000 dotted; border-bottom: 1px #000000 dotted;">
    <a href="http://websiteshairdesign.nl/" target="_blank" title="Ga naar de website">
    <img src="http://websitemedia.nl/_extern/websites/img/logo-websites.png" alt="Ga naar de website" style="font-family:calibri;text-align:right;margin:0px;padding:10px 0 10px 0;" border="0" width="232">
    </a>
    </td>
    </tr>
    <tr>
    <td colspan="2" style="font-family:calibri;color:#a3a3a3;font-size:11px;margin-top:6px;line-height:14px;">
    <br>Dit e-mailbericht is uitsluitend bestemd voor de geadresseerde. Als dit bericht niet voor u bestemd is, wordt u vriendelijk verzocht dit aan de afzender te melden. website\'s Hairdesign staat door de elektronische verzending van dit bericht niet in voor de juiste en volledige overbrenging van de inhoud, noch voor tijdige ontvangst daarvan. Voor informatie over website\'s Hairdesign raadpleegt u <a href="http://websiteshairdesign.nl/" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;" target="_BLANK">website\'s Hairdesign</a>.<br><br>
    </td>
    </tr>
    </table>';


    $contents = preg_replace('/\[contents]/',$texts, $handtekening);
    $mail->msgHTML($contents);
    $mail->AltBody = $texts;
    if(!$mail->send())
    {
        $isValid = false;
    }

    $mail = new PHPMailer;
    $mail->From = 'info@websiteshairdesign.nl';
    $mail->FromName = 'website\'s Hairdesign';
    $mail->addAddress($email);     
    $mail->isHTML(true);           
    $mail->Subject = 'Bedankt voor uw aanvraag bij website\'s Hairdesign';
    $texts = 'Geachte heer/mevrouw '.$naam.',<br /><br />
    Hartelijk dank voor uw aanvraag, wij zullen hier zo spoedig mogelijk op reageren.<br />
    <br>
    Met vriendelijke groet,
    ';
    $contents = preg_replace('/\[contents]/',$texts, $handtekening);
    $mail->msgHTML($contents);
    $mail->AltBody = $texts;
    if(!$mail->send())
        $isValid = false;
    }
    if($isValid == true) {
        $result = 'Bedankt voor uw aanvraag! Wij nemen z.s.m. contact met u op.';
    } else {
        $result = 'Vul alle velden in!';
    }

    echo $result;
twan
  • 2,450
  • 10
  • 32
  • 92
  • What does your local mail server log say? (usually in `/var/log/mail.log`) – Synchro Jan 24 '17 at 13:09
  • @Synchro I can't find them on my server. I got a mail folder but this only contains all mail addresses from this domain, not a log. – twan Jan 24 '17 at 13:15
  • I'd suggest you switch to using SMTP to localhost: include the SMTP class, call `$mail->isSMTP();`, set `$mail->Host = 'localhost';`. It should work the same way, but means you can get much more feedback on the submission process (set `$mail->SMTPDebug = 2`). – Synchro Jan 24 '17 at 13:58
  • Alright I added the lines. Where can I find the more detailed feedback? It still sends the email like before. – twan Jan 24 '17 at 14:26
  • It should be very obvious - it churns out the debug info during the send call. – Synchro Jan 24 '17 at 22:36

1 Answers1

1

If you're not using SMTP to send mail, it could be server configuration or the e-mail might be bounced because websiteshairdesign.nl is not a registered domain.

Check the mail logs on your server to check whether the email is sent successfully. Use an existing email address on the server and check if you're allowed to send mail (SPF record). Also, if you're using external mail hosting, and the domain of the email address you're sending it to is also known on the server, the email is probably delivered locally in stead of to your external server.

So try: - Sending the email from an existing email address on the server with existing domain - To a Gmail or Hotmail address to prevent local delivery.

Hope this helps.

Alfajor
  • 40
  • 1
  • 5
  • I don't know where to find the mail logs. I'm also not using external mail hosting. Do you think the mail will be bounced when a domain doesn't exist yet? I did it this way numerous times before without trouble. – twan Jan 24 '17 at 13:17
  • That depends on the spamfilter you are using. Most spamfilters check whether the domain exists, if the server is allowed to send email (SPF) etcetera. Where are you hosting and are you on a VPS? – Alfajor Jan 24 '17 at 13:50
  • I am sending from a local server, the domain is hosted on it. And I'm not on a VPS. – twan Jan 24 '17 at 13:53
  • As you're using a local server, reverse DNS is probably not set up and that could be a reason for a spamfilter to completely bounce the email without notifying you about it. Try using SMTP instead for sending emails. That's more reliable too. – Alfajor Jan 24 '17 at 14:35