How to set up and send mail for recovering account password using phpmailer in Centos 7

Hello everyone, currently my website is in need of a password recovery system by email. I’ve got the recovery site, and it’s written in php using phpmailer on xampp. It worked fine, but when I put it on VPS centos 7, it didn’t work anymore, here is my config to listen to the gmail server:

include "../vendor/autoload.php";

            $mail = new PHPMailer;
            $mail->Host = "";
            $mail->SMTPAuth = true;
            $mail->Username = "my_email_username";
            $mail->Password = "my_email_password";
            $mail->Port = 587;
            $mail->CharSet = 'UTF-8';
            $mail->From = "my_email";
            $mail->FromName = "No Reply";
            $mail->Subject = $subject;
            $mail->Body = $body;

if (!$mail->send()) {
                echo 'send_mail_failed';
            } else {
                $update_password_byEmail = "UPDATE account SET password=:gen_password WHERE name=:currentUser AND email=:currentEmail;";
                $stmt_gen_pass_update = $sqlWeb->prepare($update_password_byEmail);
                $stmt_gen_pass_update->bindValue(':gen_password', md5($password_generate));
                $stmt_gen_pass_update->bindValue(':currentUser', $usernameOfEmail);
                $stmt_gen_pass_update->bindValue(':currentEmail', $target_email);

                echo 'send_mail_successful';
        } else {
            echo 'send_mail_error';

Anyone who has experience in installing and operating it please help me find a solution to install and use phpmailer on centos 7. I am new in this field, and am trying to improve my experience. myself. Thank you very much.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

The configuration looks correct. Do you get any specific errors?

What I could suggest is testing the connection to the Google SMTP service on port 587 with telnet:

telnet 587

Let me know how it goes. Regards, Bobby