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

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

Dear friends welcome to another video tutorial!
This is Nick from and today we are going to learn how to send an email using
the Wemos D1 board which uses the ESP8266 chip. Without any further delay, let’s get
started! 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: • A Wemos D1 board, or a Wemos D1 mini
• A DHT22 sensor • A small breadboard
• Some wires The parts that we need for this project cost
around 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 DHT22 sensor to the Ground pin of the Wemos D1 board. Next you have to connect
the Vcc pin of the sensor to the 5V or 3.3V pin of the board. The last thing we have to
do is to connect the output pin 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 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 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.
All we have to do, is to create a new php script with this code which I name it send_email.php
and upload it to the webserver. I create it under my website folder so in order
to run it all we have to do is to 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 WiFi network and then we read the sensor. We save
the values, we convert them to Strings and send a GET request to the
file with the values from the sensor. That’s it. The PHP script will take the data and
it will send the email. It’s 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 webserver, so the project won’t send you an email if
you run it as it is. You have to enter your server address in the Arduino code and have
the send_email.php file uploaded to your webserver. 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 webserver. The next step is to develop
a php script that will save that data. This way we are going to build an online datalogger
with almost unlimited storage! We can achieve all that with a 5$ board! This is impressive
in my opinion! I would love to hear your opinion on that, so please post your comments in the
comments section below! Thanks! If this is your first time here, I would love
to have you subscribed. 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 will join us. Until next Saturday, Watch, Learn,
Build! [ Translating these subtitles? Add your name
here! ]


  • Özay Turay

    To be more secure instead of your own web server you should use a service like ThingSpeak ( or Adafruit IO ( with a proper API key. And rename that send_mail.php script immediatly else you can get a lot of fake emails. 😉

  • Dog Rox

    Wow that's killer! 🙂 I think it could be able to access mySQL database using PHP code. that would make it almost endless possibilities. 🙂

  • Theodosis Koulas

    Kalispera, Hello
    I have a spear arduino nano and i do not know what do with it…Can u suggest me some projects?

  • Nikos Vlagoidis

    Καλησπέρα φίλε και συγχαρητήρια για το κανάλι! Μόλις παράγγειλα το Wemos D1.
    Έχω ένα project για το οποίο πρέπει να μετράω την παροχή νερού σε ένα σωλύνα με ένα sensor και να ανεβάζω τα data μέσω wi-fi σε ένα cloud service για επεξεργασία αργότερα. Πόσο καιρό μπορεί να αντέξει με μπαταρία ; Αν υποθέσουμε ότι το σύστημα θα στέλνει δεδομένα μόνο όταν περνάει νερό και θα είναι idle τις υπόλοιπες ώρες;

  • Thomas Heaven

    Θα ητανε πολύ ενδιαφέρον εάν μπορούσες να κάνεις ένα βίντο με το online data logger.

  • Rick Sisco

    Just in CASE (silly pun intended) anyone runs into an issue getting your variables to pass through…

    $temperature = $_GET["Temperature"];
    $humidity= $_GET["Humidity"];

    in the PHP file should be…

    $temperature = $_GET["temperature"];
    $humidity= $_GET["humidity"];

  • Monica Garcia

    Excellent video

       I have a sensor but is 4 legs

    I could say as I can connect?

    Greetings and thanks for your support

    (Sorry for my English is very bad)

  • Ed19601

    great tutorial. However, it should be possible to have the ESP8266 send an email directly without having a webserver in between. After all, I can send an email from my desktop without a seperate server account, simply by logging on to say
    It will probably take a bit more programming in the ESP8266. Have to give that a try once I have more time

  • MCgamingPro

    Very nice video, just ordered a couple nodemcu boards as they are a bit cheaper, but it would be nice if you could make a video on a wifi enabled relay without the use of a raspberry pi or any other server in between. Sinexise tin kali douleia 😀

  • GKSProject

    Nice and helpful video!
    But i'm a bit confused with the Volt thing… you are using a temperature sensor with operating 5volts while wemos d1 works with 3v, i also have the same wemos d1 r2 board, a UNO R3 Sensor Shield V5 and a DS18B20 temp sensor can i connect those or ill burn everything?
    Any help appreciated!

  • Usman Chaudhary

    after how many minutes it will send mail, is it possible that server send mail automatically when it get inputs from sensor?

  • Eleongo

    Is Wemos D1 board and mini basically the same as ESP8266? Sry I ask this is because your title said ESP8266 but your video only mention these 2 components. Also, can I connect it to mobile hotspot instead of wifi router?

  • Sonyetc

    Is there a way to remove those characters that appear once we start the serial monitor in arduino IDE? or can i somehow avoid them being send via serial port to, lets say, processing ? so i would want processing to recieve data from arduino , but i want it to ignore those gibberish characters that appear at the begining … can you help?

  • Bassel Issa

    Hi, I have the same D1 board, but i can't manage to load any sketch to it. always getting errors. is there any good tutorial to run it?

  • Marc Paradis

    Hi. Trigger watchdog timer error 🙁

    3ffef4d0: 3ffee550 00000125 3ffef510 4020391d
    3ffef4e0: 3ffee45c 3ffef5d0 3ffef510 40203990
    3ffef4f0: 3ffee45c 3ffef5d0 3ffee468 402039b8
    3ffef500: 302e3435 3ffef5d0 3ffee468 40201f92
    3ffef510: 3fff071c 0000368f 00003689 40203990
    3ffef520: 3fffdad0 3ffee454 3ffef5d0 3ffee55c
    3ffef530: 3fffdad0 3ffee480 3ffef5d0 4020206e
    3ffef540: 3fff0424 0000000f 00000004 3fff0624
    3ffef550: 0000000f 00000004 3fff060c 0000000f
    3ffef560: 00000004 3ffefe9c 0000000f 00000004
    3ffef570: feefeffe 00000000 3ffee554 40202fe0
    3ffef580: feefeffe feefeffe 3ffee570 40100718

    ets Jan 8 2013,rst cause:2, boot mode:(3,7)

  • yoga muliawan

    i got this error yesterday
    warning: espcomm_sync failed
    error: espcomm_open failed
    error: espcomm_upload_mem failed
    error: espcomm_upload_mem failed
    what does it means ?

Leave a Reply

Your email address will not be published. Required fields are marked *