0

I have a contact form

<form action="contact.php" method="post" class="needs-validation" novalidate="novalidate">
    <div id="contactForm" class="form-row col-12 justify-content-left">
        <div class="row col-12 justify-content-center">
            <div id="contactFirst" class="col-3">
                <label for="firstName">First</label>
                <input type="text" class="form-control" id="firstName" name="firstName" placeholder="First Name" required="required">
                <div class="valid-feedback">
                    Looks good!
                </div>
            </div>
            <div id="contactLast" class="col-3">
                <label id="last" for="lastName">Last</label>
                <input type="text" class="form-control" id="lastName" name="lastName" placeholder="Last Name" required="required">
                <div class="valid-feedback">
                    Looks good!
                </div>
            </div>
        </div>
        <div class="row col-12 justify-content-center">
            <div id="formEmail" class="col-3">
                <label for="inputEmail">
                Email</label>
                <input type="email" class="form-control" id="email" name="email" placeholder="Email" required="required">
            </div>
            <div id="contactSelect" class="col-3">
                <label id="desiredServices" for="selectService">
                Desired Service</label>
                <select class="custom-select selectService" required="required">
                    <option value="">Select One</option>
                    <option value="1">Web Development</option>
                    <option value="2">Corporate Wellness</option>
                    <option value="3">Web Marketing</option>
                </select>
                <div class="invalid-feedback">
                    Please select your desired service!
                </div>
            </div>
        </div>
        <div class="row col-12 justify-content-center">
            <div id="contactMessage" class="form-group row col-6">
                <label for="message">Message</label>
                <textarea class="form-control" id="message" rows="3"></textarea>
            </div>
        </div>
    </div>
    <div id="contactButton" class="text-center">
        <button class="btn btn-secondary" type="submit">Submit form</button>
    </div>
</form>

After submiting it, I kept getting

closer look

contact

<?php

require 'PHPMailerAutoload.php';

$HOST       = 'smtp.gmail.com';
$PORT       = 587;
$USERNAME   = 'noreply.b@gmail.com';
$PASSWORD   = '******';
$FROM_EMAIL = $USERNAME;
$FROM_NAME  = 'T m';
$TO_EMAIL   = 'T.m.44@gmail.com';
$TO_NAME    = 'T m';
$SITE_URL   = 'https://Tm.com/';

if (isset($_POST['submit'])) {
    $firstName = $_POST['firstName'];
    $lastName  = $_POST['lastName'];
    $email     = $_POST['email'];
    $message   = $_POST['message'];
};

    $mail = new PHPMailer;

    $mail->SMTPDebug = SMTP::DEBUG_OFF;

    $mail->isSMTP();
    $mail->Host       = $HOST;
    $mail->SMTPAuth   = true;
    $mail->Username   = $USERNAME;
    $mail->Password   = $PASSWORD;
    $mail->SMTPSecure = 'tls';
    $mail->Port       = $PORT;

    $mail->setFrom($FROM_EMAIL, $FROM_NAME);
    $mail->addAddress($TO_EMAIL, $TO_NAME);

    $mail->isHTML(true);

    $mail->Subject = "Web enquiry";
    $mail->Body    = "<strong>Name:</strong><br/> <br/>".$_POST['firstName'] . ' ' . $_POST['lastName'] . '<br/><br/> <strong>Email:</strong> <br/><br/>' . $email . '<br/> <br/><strong>Message:</strong> <br/> <br/>' . $_POST['message'] . '<br/><br/> -- <br/><br/>This e-mail was sent from a contact form on ' . $SITE_URL;
    $mail->AltBody = "From: non-HTML mail".$_POST['message'];

        if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
        echo 'Message has been sent';
        };
?>

I am hosting in Ubuntu VM using Apache.

What should I check to debug this further ?

Community
  • 1
  • 1
code-8
  • 54,650
  • 106
  • 352
  • 604
  • [HTTP 500](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_Error) is a generic server-side error message. On its own it doesn't tell us anything useful. Any time you see this your first step should be to check your error logs for more detail. – ChrisGPT was on strike Dec 05 '19 at 03:15
  • Apache or PhP log ? – code-8 Dec 05 '19 at 03:15
  • This may not be related, but I strongly urge you to use a real mail gateway instead of Gmail. It's not designed for programmatic use. – ChrisGPT was on strike Dec 05 '19 at 03:16
  • It depends how your web server is configured. Start by reading the Apache error log and go from there. If you've got other error logs configured, read them too. – ChrisGPT was on strike Dec 05 '19 at 03:17

0 Answers0