My contact form doesn't send me messages


#1

Hi guys,

I have this single page website http://yourexecutivechair.com

I got a problem withe its contact form, and I read the following article:
https://infinityfree.net/support/how-to-send-email-with-gmail-smtp/

I applied all the steps: I uploaded PHPMailer file to my htdocs folder. I let less secure apps use my Gmail account ( yourexecutivechair@gmail.com) which is the same account I use for receiving messages from the website. I also created the php script to use PHPMailer. I am attaching this script to this post.

I think the problem is with the php I created. Could you please help me to fix it?

Many Thanks.
Hananneh

[php]<?php

date_default_timezone_set(‘Etc/UTC’);

// Edit this path if PHPMailer is in a different location.
require ‘PHPMailer/PHPMailerAutoload.php’;

$mail = new PHPMailer;
$mail->isSMTP();

/*

  • Server Configuration
    */

$mail->Host = ‘smtp.gmail.com’; // Which SMTP server to use.
$mail->Port = 587; // Which port to use, 587 is the default port for TLS security.
$mail->SMTPSecure = ‘tls’; // Which security method to use. TLS is most secure.
$mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
$mail->Username = "yourexecutivechair@gmail.com"; // Your Gmail address.
$mail->Password = “mypassword”; // Your Gmail login password or App Specific Password.

$errorMSG = “”;

// NAME
if (empty($_POST[“name”])) {
$errorMSG = "Name is required ";
} else {
$name = $_POST[“name”];
}

// EMAIL
if (empty($_POST[“email”])) {
$errorMSG .= "Email is required ";
} else {
$email = $_POST[“email”];
}

// MSG SUBJECT
if (empty($_POST[“msg_subject”])) {
$errorMSG .= "Subject is required ";
} else {
$msg_subject = $_POST[“msg_subject”];
}

// MESSAGE
if (empty($_POST[“message”])) {
$errorMSG .= "Message is required ";
} else {
$message = $_POST[“message”];
}

// prepare email body text
$Body = “”;
$Body .= "Name: ";
$Body .= $name;
$Body .= “\n”;
$Body .= "Email: ";
$Body .= $email;
$Body .= “\n”;
$Body .= "Subject: ";
$Body .= $msg_subject;
$Body .= “\n”;
$Body .= "Message: ";
$Body .= $message;
$Body .= “\n”;

// send email
$mail->setFrom(‘yourexecutivechair@gmail.com’, ‘Your Executive Chair’);
$mail->addAddress(‘hannaneh.rashidi@gmail.com’, ‘Hannaneh’);
$mail->addReplyTo($email, $name); // This line ensures you can hit Reply from your inbox and have it send to the contactor.
$mail->Subject = $msg_subject;
$mail->Body = $Body;

if ($mail->send()) {
echo “Your message was sent successfully!”;
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}

?>[/php]


#2

What does it do? If there is an error, it should show the error message, though you should be logging those, not displaying them to the user.