It’s a short write and this is mainly serving as our reference since … so … it’s going to be a bit technical… the good thing is that the part I isn’t that complex at all. Thus, if you aren’t in the role of handling the domain name emails, you might feel it’s boring. However, it may still help you in the future if you have any needs of this kind.
Reasons – Why Using Domain Name Email Address
When it’s about to wrap up projects and bring it to the public, one of the most important tasks regarding to communicating with your projects potential users or visitors in general is that you need to have a email server to handle the job. There are lots of ways to do that. If you are using PHP, you can use its mail() function to do the biddings. By the way, since PHP is the most wildly used language, we are going to just focus on PHP. So … back to the point that you can also use other classes/plugins which just wrap PHP’s mail() function and present it in a much more useful and fancy way to get accomplish the mission.
However, there is a bit hiccup if you pay attention to.
PHP mail() function –
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
It does NOT matter which “from address” you set on the PHP mail() function header (string $additional_headers), email service providers (from now on, I am going to just refer to GMail since it’s the most popular and most used email service worldwide. Honestly… who isn’t using it? right?) will NOT show the “from address” you set on the header but the domain of the email server which you sent your email from. An example below,
Sending emails from “thisiswww.com” domain. Therefore, the email “from address” we set up is “firstname.lastname@example.org”.
$to = “Josh@gmail.com”;
$subject = “Welcome to This is What We Want”;
$message = “Hello, Josh! \nWelcome to this is want we want……”;
$headers = “From: email@example.com“;
If you execute it, you will see (assuming you are Josh and your email address is Josh@gmail.com) the from address isn’t the “from address” that has been set up. Even if you have set up your own SMTP server, it will show the domain of your SMTP server not the “from address” you configured.
HOW TO USE GMAIL AS YOUR SMTP SERVER – Step by Step
Step 0 – why you need to?
Because it’s legit and, basically, we are all perfectionists who would like to go extra mile all the time. Also, you need to let your users know that you (the domain) are the one who really sent those emails.
Step 1 – YOU NEED TO OWN YOUR SMTP SERVER
Either set up an SMTP server yourself or buy one from one of many hosting companies out there on the market. We suggest that you buy one for this purpose. Reasons are … 1) this isn’t your core (project-wise). You need to put your time onto better uses. 2) it will reduce a lot (a llllooootttt) of headaches later on.
Step 2 – Where (and How) To Buy An Smtp Server
You can (and should) just buy a Web Hosting package and set it up. It’s easier and you will have more control over other features which you might have some other uses.
Suggested Hosting Companies
There are bunch of them out there that you can choose from. The SMTP server here is only going to be acting an authentication proxy for ONCE. And after that, everything will go through GMail server. Therefore, you don’t really need to compare the server speed and other specs here.
Step 3 – Set Up “send email from different address or alias”
Step 4 – Turn on “lesser secured app”
This is a MUST.
Step 5 – Turn on “2 steps verification”
If you are using Laravel, you can follow the instructions below,
1) enable the 2-step verification with google HERE
2) Create App Password to be use by your system HERE
3) Generate App Password – You can select Others (custom name) and clicked generate
4) Edit your env file – Went to your env file in Laravel and edited this
5) Restarted your apache server and boom! It magically works 🙂
Now, you can sent emails from the alias you set on your Gmail account. By the way, if you are using Google App (now is “G Suite”) email account(s), this feature won’t be available to you. Since you are launching a service/product, you should apply for another Gmail account solely for this purpose.
We will have later series to talk about how to hook up Amazon SES (Simple Email Service) with GMail in the next couple of days.