I was struggling with getting contact form to actually send mail to me. Funny thing about coding, you have to get each step correct or nothing will work. First, I am new to PHPMailer and this simple concept just didn't get in my brain right away. I was running the command... composer require phpmailer/phpmailer in the /root/ folder on my server. Like I said, I'm new to using PHPMailer. I didn't realize that there were folders being created in the "wrong" folder and basically useless to me for the rest of the tutorial I was watching. SSH to your server. apt install composer cd /var/www/example.com/web/ composer require phpmailer/phpmailer Since I only have a root account on my server I received a warning... Do not run Composer as root/super user! See https://getcomposer.org/root for details I read the info in the link and decided to go ahead and continue as root user. My server is setup with only a root user and password NOT allowed. Only login by SSH key. If this is a bad practice, please tell me, and suggest the better practice. Thanks In the video the content creator links to the files he used in the video. https://gist.github.com/daveh/1164348fe21a6e7363d28c7b94c9eb3f You literally just create the 3 files as he shows in the video.. One change I had to make from his files though to make it work with SSL on port 465 instead of STARTTLS on port 587. His example... $mail->Host = "smtp.example.com"; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 587; I changed to ... $mail->Host = 'smtp.example.com'; $mail->SMTPSecure = 'ssl'; $mail->Port = 465; Also, I learned something else from one of his other videos. I have a single quote in my password for my SMTP user. In PHP, single quotes are used to quote the password. Having a single quote IN my password breaks the PHP script. I learned from him that you can just add a \ in front of the single quote inside of the password to make PHP understand what it is reading. If you password is 123'456 Just add a \ in front of the ' Like this 123\'456 and it will work.
I forgot to mention that you will also have to chown the folder that is created by composer, since it is run as root. Well, I ran the command as root, so I had to chown the folder. while you are in the web folder you can ls -lsa to see who owns the other files and folders in the web folder. then you'll want to chown the vendor folder like this... chown -R web1:client1 vendor