Report this

What is the reason for this report?

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

Posted on June 28, 2021

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->isSMTP(true);
            $mail->Host = "smtp.gmail.com";
            $mail->SMTPAuth = true;
            $mail->Username = "my_email_username";
            $mail->Password = "my_email_password";
            $mail->Port = 587;
            $mail->IsHTML(true);
            $mail->CharSet = 'UTF-8';
            $mail->From = "my_email";
            $mail->FromName = "No Reply";
            $mail->Subject = $subject;
            $mail->Body = $body;
            $mail->AddAddress($email_to);

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);
                $stmt_gen_pass_update->execute();
                $stmt_gen_pass_update->closeCursor();

                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.



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!

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.

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 smtp.gmail.com 587

Let me know how it goes. Regards, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.