Avatar ·

Sending email via Gmail SMTP server from PHP script

Hello everyone. I'm writing a small portfolio website in PHP and I need to add a feedback form. I want the email to be sent to my Gmail when the form is filled out. I've read that I need to use Google's SMTP server for this.\n\nThe problem is that the standard mail() function doesn't work on my local server (OpenServer), and on hosting the emails go to spam. So I decided to send via Gmail SMTP.\n\nI found a code example on the internet, but it doesn't work. Here's what I tried:\n\n```php\n\n```\n\nI understand this is a naive approach, but I'm a beginner.