0

On my website I have three forms. Each has an almost equal php file behind it, just with different $content. All of these run fine upon submitting, confirming the mail's been sent, but from only one the mail is actually delivered.

Here's the file that runs fine, but no mail comes through:

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // access
    $secretKey = 'secretKey';
    $captcha = $_POST['g-recaptcha-response'];

    if(!$captcha){
      echo '<p class="alert alert-warning">Wil je de captcha nog even aanvinken?</p>';
      exit;
    }

    $mail_to = "myemail@email.com";
    
    # Sender Data
    $naam = $_POST['naam']; 
    $telNr = $_POST['telNr'];
    $eMail = $_POST['eMail'];
    $day = $_POST['doDay'];
    $month = $_POST['doMonth'];
    $year = $_POST['doYear'];
    $massage = $_POST['doMassage'];
    $timeslot = $_POST['timeslot'];
            
    if (empty( $naam) OR !filter_var($eMail, FILTER_VALIDATE_EMAIL) OR empty($telNr)) {
        # Set a 400 (bad request) response code and exit.
        http_response_code(400);
        echo '<p class="alert alert-warning">Oei, storing... Zou je willen checken of je alles (correct) hebt ingevuld?</p>';
        exit;
    }

    $ip = $_SERVER['REMOTE_ADDR'];
    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
    $responseKeys = json_decode($response,true);

    if(intval($responseKeys["success"]) !== 1) {
      echo '<p class="alert alert-warning">Wil je de captcha nog even aanvinken?</p>';
    } else {
        # Mail Content
        $content = "$naam wil graag een afspraak maken op $day - $month - $year om $timeslot";
        $content .= "Graag een bevestiging sturen naar $email of naar $telNr\n\n";
        $content .= "Het gaat om een $massage";

        # email headers.
        $headers = "From: $naam <$email>";
        $subject = "$naam wil graag een $massage!";

        # Send the email.
        $success = mail($mail_to, $subject, $content, $headers);
        if ($success) {
            # Set a 200 (okay) response code.
            http_response_code(200);
            echo '<p class="alert alert-success">Bedankt! Je krijgt z.s.m. een e-mail ter bevestiging. Je gaat zo automatisch terug naar de site.</p>';
        } else {
            # Set a 500 (internal server error) response code.
            http_response_code(500);
            echo '<p class="alert alert-warning">Oei, storing... Helaas is je bericht niet verstuurd.</p>';
        }
    }

} else {
    # Not a POST request, set a 403 (forbidden) response code.
    http_response_code(403);
    echo '<p class="alert alert-warning">Oei, er ging \'iets\' mis... Misschien kun je het nog eens proberen.</p>';
}

?>

I think the syntax is fine right? Why isn't the mail getting through?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • maybe you need to check the domain which you send emails from configration . its probably blocked by internet ISP's try checking mx on this site https://mxtoolbox.com/ – Ahmed amin shahin Oct 11 '21 at 09:18
  • What have you tried to resolve the problem? Does your server contain any logs for these mails? – Nico Haase Oct 11 '21 at 09:18

0 Answers0