Sending Gmail with Swiftmailer

Anthony kimanzi
2 min readDec 21, 2019

--

adding mailing functionality to website is quite an essential part of website development. most website have this sections either in the contact us section, feedback sections among other sections like registration and sign up. It can be quite a hustle when you are beginner because we have you need to have a solutions that works without too much hassle, I prefer swift mailer because i find it straight of the box solutions compared to vanilla solutions and PHPMAILER(you are allowed to have an alternative view who cares though ). This tutorial assumes you have installed your XAMPP or whatever server you have there and also prior knowledge on PHP is a bonus .

To avoid too much stories let’s get straight to it.

Steps

  1. Download swiftmailer
  2. create mailing script
  3. Enable your gmail account for IMAP
  4. Testing your mailing script

1. Download swiftmailer

In your htdocs folder create your working director in my case i have named it sendmail.

inside the sendmail directory install swiftmailer with composer. Check also on the swiftmailer official website here

```php
composer require “swiftmailer/swiftmailer:⁶.0”
```

2. Create mailing script

This is a simple script which contains mailing function and html form, the message is hardcoded but for demonstration purpose. create this script inside your working directory eg sendmail

3. Enable your gmail account for IMAP

after you have created this script use the following address to enable IMAP settings due to google security settings

https://www.google.com/settings/security/lesssecureapps

4. Testing your mailing script

Run your script on local host and enjoying using it. you can create complicated mailing systems with swiftmailer among other things. Happy coding

Originally published at https://dev.to on December 21, 2019.

--

--

Anthony kimanzi

I am Anthony Kimanzi a masters students in Energy Informatics at FHOOE Austria. Software developer at Neoom Austria.I develop in Python, PHP/laravel & Java