PHP | not receiving email

Good day,

i am very new at coding. just finished my first website, containing a form; but i am not receiving the email when hitting submit (accept)
jtconfirmation.co.za
`<?php

use PHPMailer\PHPMailer\PHPMailer;
require DIR . ‘/vendor/autoload.php’;

$errors = [];
$errorMessage = ‘’;

if (!empty($_POST)) {
$name = $_POST[‘name’];
$email = $_POST[‘email’];

if (empty($name)) {
    $errors[] = 'Name is empty';
}

if (empty($email)) {
    $errors[] = 'Email is empty';
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    $errors[] = 'Email is invalid';
}


if (!empty($errors)) {
    $allErrors = join('<br/>', $errors);
    $errorMessage = "<p style='color: red;'>{$allErrors}</p>";
} else {
    $mail = new PHPMailer();

    // specify SMTP credentials
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = '[email protected]';
    $mail->Password = 'P@ssword123';
    $mail->SMTPSecure = 'tls';
    $mail->Port = 587;

    $mail->setFrom($email, 'Mailtrap Website');
    $mail->addAddress('[email protected]    ', 'Me');
    $mail->Subject = 'RSVP Church';

    // Enable HTML if needed
    $mail->isHTML(true);

    $bodyParagraphs = ["Name: {$name}", "Email: {$email}", "Message:", nl2br($message)];
    $body = join('<br />', $bodyParagraphs);
    $mail->Body = $body;

    echo $body;
    if($mail->send()){

        header('Location: thank-you.html'); // redirect to 'thank you' page
    } else {
        $errorMessage = 'Oops, something went wrong. Mailer Error: ' . $mail->ErrorInfo;
    }
}

}

?>`

Names Confirmation RSVP
Home
        <div class="info">
            <h1>RSVP</h1>
            <h2>for the Confirmation Service of</h2>
            <h1>Name</h1>
            <p class="line">________________________________________</p>
            <h2>The Details</h2>
            <p>Sunday, 28 February 2021</p>
            <p>10:00 AM</p>
            <p>Please RSVP by 15 February 2021</p>
            <h2>Confirmation Service</h2>
            <p><a href="#" target="_blank">
                    Calvyn Protestant Church Diep River</a></p>
            <p>10 Keswick St, Elfindale</p>
            <p class="line">________________________________________</p>
            
            <input type="text" value="name" placeholder="Name">
            <input type="email" value="email" placeholder="Email">
        </div>
        <?php echo((!empty($errorMessage)) ? $errorMessage : '') ?>
        <button type="submit" class="accept" value="Send">Accept</button>
        <button type="submit" class="regret" value="Send">Regret</button>
    </div>
</form>

<script src="//cdnjs.cloudflare.com/ajax/libs/validate.js/0.13.1/validate.min.js"></script>

Enable PHPMailer debug mode by adding:

$mail->SMTPDebug = 2;

But DO not leave that in on a production website!

Are you using a self signed SSL certificate if you are, you will also need to add:

$mail->SMTPOptions = ['ssl' => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true]];
1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service