0

Has anyone used "Perfect Contact Us Form" by forest_of_code/PerfectCode?

I keep getting the error: "Oops! Something not right. Please check your details."

I followed the coder's instructions step by step and checked multiple times that I have not mistyped soemthing. I am also sure that my host allows mail over SMTP. I am trying to send mail using the gmail smtp. I enabled "allow less secure apps" on my account and i am not using 2AuthFactor.

These are my current Settings (the XXXX are to hide my info, in my files im using my actual info):

function smtpContact($to, $subject, $name, $phone, $message){
            require_once 'PHPMailer/PHPMailerAutoload.php';
            $response = array();
            //Create a new PHPMailer instance
            $mail = new PHPMailer;
            $mail->isSMTP();
            $mail->SMTPDebug = 0;
            $mail->Debugoutput = 'html';
            $mail->Host = "smtp.gmail.com";
            $mail->Port = 587;
            $mail->SMTPAuth = true;
            $mail->Username = "XXXXXX@gmail.com";
            $mail->Password = "xxxxxxxxxxxxx";
            $mail->setFrom($to, $name);
            $mail->addAddress('XXXXXXXX@gmail.com', 'XXXXX');
            $mail->Subject = $subject;
            $message =  '<div  style="background:#F5F5F5; padding:10px;">
                            <p>'.$message.'</p><br />
                            <div>Name : '.$name.'</div><br />
                            <div>Phone : '.$phone.'</div><br />
                        </div>';
            $mail->msgHTML($message);
            $mail->AltBody = 'This is a plain-text message body';
            $mail->SMTPOptions = array(
                'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        ); 
        if (!$mail->send()){
            // For Debugging
            //return "Mailer Error: " . $mail->ErrorInfo;
            $response['error'] = 'Something not right. Please check your details.';
        }else{
            $response['success'] = 'Your email has been sent successfully.';
        }
        echo json_encode($response, JSON_PRETTY_PRINT);
    }/*...ends[contactus]...*/
Synn
  • 3
  • 4
  • It looks like the mail object you have has an ErrorInfo property. You might want to start there and get the message. That will help. – Ctznkane525 Dec 18 '17 at 01:08
  • i have tried that but all it gives is, is wrong credentials which i know for a fact isnt. I have just stumbled upon an almost 5 year old post that mentioned that this line was the issue `$mail->isSMTP();`. I deleted it and It works perfectly fine. Been trying to find the solution to this for daaaaays – Synn Dec 18 '17 at 01:15
  • yeah just realized that after i asked the question. i been looking around to try and delete this post but i cant find it anywhere. im still new here so it may take me a bit to find out how to delete this – Synn Dec 18 '17 at 01:28

1 Answers1

0

This has been answered before about 5 years ago. I am posting this again just incase people are still running into this issue like i did. I found the solution here: send email using Gmail SMTP server through PHP Mailer

Basically all I had to do was delete this line $mail->isSMTP();

I am grateful for that user, i have been looking for a solution for several days until I stumbled upon his question, that he answered on his own :D

Synn
  • 3
  • 4