0

$USD

$USD
TUTORIALS ESP8266

Arduino ESP8266 Tutorial: Send an email easily with your Wemos D1 board using a PHP script!

DFRobot May 08 2018 646

In this video we are going to learn how to send email using an ESP8266 based board like the Wemos D1. As you are going to find out it is very easy and it won't take us more than 10 minutes.
Having a WiFi enabled board, like the ESP8266 enable us to do many more things. I wanted to learn how to send emails from the Wemos Board in order to get reports from my projects to my email account easily. As you are going to find out, it is very easy! 

I have built a simple project in order to demonstrate what I mean. I have connected a DHT22 temperature and humidity sensor, and when the project boots up, it measures the temperature and the humidity and sends the data to my email address! This functionality can be very useful in some projects. As you are going to find out is very easy add such functionality in your Arduino projects. But let's see how to build this project.
The parts needed in order to build this project are these:

The code of the project consists of two parts, the Arduino code, and the server code. We are not sending the email directly from the board to the email address but I used another solution which in my opinion is much easier to implement. The board all it does is to gather the data and send them to a remote web server. There, a simple php script will send that data to any email address we want. This way the Arduino code is extremely easy as you are going to see and we have already build a project like this. The php code is also extremely easy, it is 7 lines of code. 

Of course, you must have a web server available if you are going to use this solution. Since 2006 I use bluehost.com as my hosting provider and I host all my websites there. So, since I had a webserver available this solution was the easiest for me to implement. It took me less than hour to make this project work. If you don't have a webserver available with around 4$ per month you can have your own bluehost account. You can find a link for it in the description of the video. Of course, you can use any other host you like, I use bluehost for over 10 years that's why I recommend it.
--------------------
BLUEHOST WEBSERVER
Bluehost: http://bit.ly/BluehostAccount

Dear friends. Welcome to another video tutorial. This is Nick from educ8s.tv and today we are going to learn how to send an email using Wemos D1 board which uses the ESP8266 chip.Without any further delay let’s get started. Having a Wi Fi enabled board like the ESP8266 enables us to do many things. I wanted to learn how to send emails from the Wemos Board in order to get reports from my projects to my mail account easily. As you are going to find out, it is very easy. I have built a simple project in order to demonstrate what I mean. I have connected a DHT22 temperature and humidity sensor and when the project boots up, it measures the temperature and the humidity and sends the data to my email address.

This functionality can be very useful in some projects. As you are going to find out, it is very easy add such functionality in your Arduino projects. But let’s see how to build this project. The parts needed in order to build this project are these

Wemos D1: http://educ8s.tv/part/WemosD1
Wemos D1 mini: http://educ8s.tv/part/D1Mini
DHT22: http://educ8s.tv/part/DHT22
Small Breadboard: http://educ8s.tv/part/SmallBreadboard
Wires: http://educ8s.tv/part/Wires
Xiaomi PowerBank: http://educ8s.tv/part/Powerbank
Bluehost: http://bit.ly/BluehostAccount
The parts that we need for the project cost $15 if you use the Wemos D1 board or around $10 if you use the Wemos D1 mini board. You can find links for all the parts in the description of the video. The connection of the parts is extremely easy. All you have to do is to connect the ground pin of the DHT 22 sensor to the Ground pin of the Wemos D1 board.

Next you have to connect the Vcc pin of the sensor to the 5V or3.3V pin of the board. The last thing we have to do is to connect the output of the sensor to digital pin 8 of the board. Now we are ready to power up the project. After a few seconds, a new email arrives with the readings that the sensor measured.

Let’s now see the software side of the project. The code of the project comprises of two parts- the Arduino code and the Server code. We are not sending email directly from the board to the email address but I used another solution which in my opinion is much easier to implement. The board all it does is to gather the data and send them to a remote web server. There, a simple PHP script will send that data to any email address we want.

This way, the Arduino code is extremely easy as you are going to see. We have already built a project like this. The PHP code is also extremely easy; it is 7 lines of code. Of course you must have a web server available if you are going to use this solution. Since 2006 I use bluehost.com as my hosting provider and I host all my websites there. So since I had a web server available this solution, was the easiest for me to implement. It took me less than an hour to make this project work.

If you do not have a web server available with around $4 per month, you can have your own blue host account. We can find a link for it in the description of the video. Of course, you can use any other host you like, I used blue host for 10 years that why I recommend it. All we have to do is create a new PHP script with this code which I named send _email PHP and upload it to the web server. I create it under my educ8s.tv website folder, so in order to run it.

We all have to do is enter this address followed by some variables. What we are doing here is we provide 2 variables to the PHP script manually. We provide temperature and humidity. The PHP script will take the variables and it will send them with an email. It is very easy. Can you now understand what the Arduino has to do? It only has to create this web address with the readings from the sensor and then make a Get request to that web page. The PHP script will automatically get the data and send them with an email.

That’s exactly what we are doing in the Arduino code. We first connect to the Wi Fi network and then we read the sensor. We save the values; we convert them to strings and send a Get request to the educ8s.tv file with the values from the sensor. That’s it. The PHP script will take the data and it will send the email. It is that easy. As always, you can find the code of the project both the PHP and the Arduino code in the description of the video. For obvious reasons, I have removed the send_email.php file from my web server so that project won’t send you an email if you run as it is. You have to enter your server address in the Arduino code and have the send_email.php file uploaded to your web server.

As you can see we can now easily send email from our internet enabled Arduino projects .With this project, we have also moved one step forward. We now know how to send data to a remote web server. The next step is to develop a PHP script that will save that data. This way we are going to build an online data logger with almost unlimited storage. We can achieve all that with a $5 board. This is impressive in my opinion. Please post your comments in the comment section below. Thanks. In this channel I post videos about DIY projects every Saturday. I love making things and I believe that anyone can make things, anyone can become a maker. That’s why I created this channel in order to share my knowledge with the community and learn from the community. I hope you enjoyed it.

This video is made by educ8s.tv, click here to see the original youtube video.