To send email, you need access to a mail server. While it is possible to set up a mail server on your own computer, in this course, we assume you are sending email using a hosted email service, such as hotmail.com, gmail.com, or yahoo.com. For production websites, your hosting provider or IT team would provide you with the settings you need to connect to your mail server.
Be Careful with your Password!
Storing your personal password in a file is risky. If you choose to do it for this course, you should be sure to remove it once you are done. A safer alternative is to create another free email account with a different password for testing.
A Note on gmail.com
To send email with PHP and gmail.com, you will need to enable less secure apps in your gmail.com account. One option is to enable less secure apps to test your code and then disable it again when you're done.
See https://support.google.com/accounts/answer/6010255 to learn more about this.
We need to let
PHPMailer know what mail server we are using, how to log in, and from whom to send emails. We will use a function for creating a new reusable, pre-configured
PHPMailer object in the mail_config.php file in our includes directory outside of the web root.