By FringeAvenue
I setup Postfix on my server which also runs my associated website. After sending a test email I received a message stating the server was associated with spam and blocked from sending to gmail. I cannot afford a dedicated server at this stage of my development but I need a method to send emails for forgotten passwords, 2FA and occasional newsletters and they need to come from my domain name. Can I do this from PHP using Google’s SMTP server and my domain name? I’m not finding good documentation on that process.
Thanks!
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!
Hi @FringeAvenue,
Yes, you can do that. You can configure your PHP to use SMTP from another server and send e-mails from it, for instance, Google. There are two basic ways of sending emails with PHP: a built-in mail function and external mail packages.
PHP’s built-in mail function () is very simple, but it provides limited functionality for sending emails. You won’t be able to add attachments to your email, and building a beautiful HTML template with embedded images will be a tricky task as well.
The other side of the PHP mail function () is that the email is sent from your web server, which may cause issues with deliverability due to security concerns such as suspicion of spam and blacklisting. The best way to overcome this problem is sending messages via an SMTP server, however, this functionality is limited as well. You can configure SMTP with some external packages, I recommend you to give the following article a read - PHP With SMTP
Regards, KFSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.