{"id":90022,"date":"2023-03-26T23:20:42","date_gmt":"2023-03-26T23:20:42","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=90022"},"modified":"2023-03-26T23:25:05","modified_gmt":"2023-03-26T23:25:05","slug":"esp32-esp8266-send-email-notification","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-esp8266-send-email-notification\/","title":{"rendered":"ESP32\/ESP8266 Send Email Notification using PHP Script"},"content":{"rendered":"\n<p>In this project, you\u2019ll build an ESP32 or ESP8266 client that makes an HTTP POST request to a PHP script to send an email notification with sensor readings.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Send-Email-ESP32-ESP8266-PHP-Script.png?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Send Email Notification using PHP Script\" class=\"wp-image-129640\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Send-Email-ESP32-ESP8266-PHP-Script.png?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Send-Email-ESP32-ESP8266-PHP-Script.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Send-Email-ESP32-ESP8266-PHP-Script.png?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Send-Email-ESP32-ESP8266-PHP-Script.png?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\"><em>Updated on 27 March 2023<\/em><\/p>\n\n\n\n<p>You can also set a threshold value, so your email notification is only sent if the temperature\/humidity\/pressure is above a certain value.<\/p>\n\n\n\n<p>As an example, we&#8217;ll be using a BME280 sensor connected to an ESP32 or ESP8266 board. You can modify the code provided to send readings from a different sensor or even use multiple boards.<\/p>\n\n\n\n<p>This is a great way to send email notifications using the ESP32 or ESP8266 without relying on IFTTT or an SMTP server.<\/p>\n\n\n\n<p>In order to build this project, you will:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><span style=\"font-size: inherit; background-color: initial;\"><a href=\"#host-php-application\" title=\"\">Host a server and setup a domain name<\/a><\/span><\/li>\n\n\n\n<li><a href=\"#php-script-email-notification\" title=\"\">Create PHP script to send email notifications<\/a><\/li>\n\n\n\n<li><a href=\"#set-up-esp32-esp8266\" title=\"\">Program ESP32 or ESP8266 with Arduino IDE<\/a><\/li>\n<\/ol>\n\n\n\n<p>This project is also a great addition to build upon our previous projects:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-mysql-database-php\/\">ESP32\/ESP8266 Insert Data into MySQL Database using PHP and Arduino IDE<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/visualize-esp32-esp8266-sensor-readings-from-anywhere\/\">Visualize Your Sensor Readings from Anywhere in the World<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"host-php-application\">1. Hosting Your PHP Application<\/h2>\n\n\n\n<p>The goal of this project is to have your own domain name and hosting account that allows you to send email notifications (without using an SMTP server, IFTTT, etc&#8230;). <\/p>\n\n\n\n<p>Here&#8217;s a high-level overview of how the project works:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"729\" height=\"564\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-ESP8266-send-email-notification-with-sensor-readings-overview.png?resize=729%2C564&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Hosting PHP Application to send email of ESP32 or ESP8266 BME280 Sensor Readings\" class=\"wp-image-90025\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-ESP8266-send-email-notification-with-sensor-readings-overview.png?w=729&amp;quality=100&amp;strip=all&amp;ssl=1 729w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-ESP8266-send-email-notification-with-sensor-readings-overview.png?resize=300%2C232&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 729px) 100vw, 729px\" \/><\/figure><\/div>\n\n\n<p>I recommend using one of the following hosting services that can handle all the project requirements:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/randomnerdtutorials.com\/bluehost\" target=\"_blank\">Bluehost (user-friendly with cPanel)<\/a>: free domain name when you sign up for the 3-year plan. I recommend choosing the unlimited websites option;<\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" style=\"font-size: inherit; background-color: initial;\" href=\"https:\/\/randomnerdtutorials.com\/digitalocean\" target=\"_blank\">Digital Ocean<\/a><span style=\"font-size: inherit; background-color: initial;\">: Linux server that you manage through a command line. I only recommended this option for advanced users.<\/span><\/li>\n<\/ul>\n\n\n\n<p>Those two services are the ones that I use and personally recommend, but you can use any other hosting service. Any hosting service that offers PHP and MySQL will work with this tutorial. If you don&#8217;t have a hosting account, I recommend <a href=\"https:\/\/randomnerdtutorials.com\/bluehost\">signing up for Bluehost<\/a>.<\/p>\n\n\n\n<p style=\"text-align:center\"><a href=\"https:\/\/randomnerdtutorials.com\/bluehost\" target=\"_blank\" class=\"button\" rel=\"noopener noreferrer\">Get Hosting and Domain Name with Bluehost \u00bb<\/a><\/p>\n\n\n\n<p>When buying a hosting account, you&#8217;ll also have to purchase a domain name. If you like our projects, you might consider signing up for one of the recommended hosting services, because you&#8217;ll be supporting our work.<\/p>\n\n\n\n<p class=\"rntbox rntclgreen\"><strong>Note: <\/strong> you can also run a <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-apache-mysql-php-lamp-server\/\">LAMP (Linux, Apache, MySQL, PHP) server<\/a> on a Raspberry Pi, but it can&#8217;t send emails standalone. To send an email with a Raspberry Pi using PHP, you need to use an SMTP (Simple Mail Transfer Protocol) server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"php-script-email-notification\">2. PHP Script HTTP &#8211; Send Email Notification<\/h2>\n\n\n\n<p>After signing up for a <a rel=\"noreferrer noopener\" aria-label=\"hosting and setting up a domain name (opens in a new tab)\" href=\"https:\/\/randomnerdtutorials.com\/bluehost\" target=\"_blank\">hosting account and setting up a domain name<\/a>, you can login to your cPanel or similar dashboard.<\/p>\n\n\n\n<p>After that, follow the next steps to create a PHP script that is responsible for receiving incoming requests from the ESP32\/ESP8266 and sending an email. <\/p>\n\n\n\n<p>If you&#8217;re using a hosting provider with cPanel, go to Advanced and search for &#8220;<strong>File Manager<\/strong>&#8220;:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"794\" height=\"543\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/cpanel-bluehost-file-manager.jpg?resize=794%2C543&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 CPanel Open Create Edit PHP Files\" class=\"wp-image-90026\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/cpanel-bluehost-file-manager.jpg?w=794&amp;quality=100&amp;strip=all&amp;ssl=1 794w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/cpanel-bluehost-file-manager.jpg?resize=300%2C205&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/cpanel-bluehost-file-manager.jpg?resize=768%2C525&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 794px) 100vw, 794px\" \/><\/figure><\/div>\n\n\n<p>Then, select the <strong>public_html<\/strong> option and press the &#8220;<strong>+ File<\/strong>&#8221; button to create a new <em>.php<\/em> file.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"849\" height=\"346\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-ESP8266-CPanel-Create-New-PHP-File.png?resize=849%2C346&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 CPanel Create New PHP File\" class=\"wp-image-85940\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-ESP8266-CPanel-Create-New-PHP-File.png?w=849&amp;quality=100&amp;strip=all&amp;ssl=1 849w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-ESP8266-CPanel-Create-New-PHP-File.png?resize=300%2C122&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-ESP8266-CPanel-Create-New-PHP-File.png?resize=768%2C313&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\"><strong>Note: <\/strong> if you&#8217;re following this tutorial and you&#8217;re not familiar with PHP, I recommend creating that exact file. Otherwise, you&#8217;ll need to modify the ESP sketch provided with a different URL path. <\/p>\n\n\n\n<p>Create a new file in <strong>\/public_html<\/strong> with this exact name and extension: <em>email-notification.php<\/em><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"496\" height=\"246\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/email-notification-php-file-new-created.png?resize=496%2C246&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"PHP Create New file email notification\" class=\"wp-image-90027\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/email-notification-php-file-new-created.png?w=496&amp;quality=100&amp;strip=all&amp;ssl=1 496w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/email-notification-php-file-new-created.png?resize=300%2C149&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 496px) 100vw, 496px\" \/><\/figure><\/div>\n\n\n<p>Edit the newly created file (<em>email-notification.php<\/em>) and copy the following script:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">&lt;?php\n\n\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-esp8266-send-email-notification\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files.\n  \n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n*\/\n\n\/\/ Receiver Email Address (where to send email notification)\n$email_address = &quot;YourEmailAddress@example.com&quot;;\n\n\/\/ Keep this API Key value to be compatible with the ESP code provided in the project page. If you change this value, the ESP sketch needs to match\n$api_key_value = &quot;tPmAT5Ab3j7F9&quot;;\n\n$api_key = $value1 = $value2 = $value3 = &quot;&quot;;\n\nif ($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;) {\n    $api_key = test_input($_POST[&quot;api_key&quot;]);\n    if($api_key == $api_key_value) {\n        $value1 = test_input($_POST[&quot;value1&quot;]);\n        $value2 = test_input($_POST[&quot;value2&quot;]);\n        $value3 = test_input($_POST[&quot;value3&quot;]);\n        \n        \/\/ Email message\n        $email_msg = &quot;Temperature: &quot; . $value1 . &quot;\u00baC\\nHumidity: &quot; . $value2 . &quot;%\\nPressure: &quot; . $value3 . &quot;hPa&quot;;\n        \n        \/\/ Use wordwrap() if lines are longer than 70 characters\n        $email_msg = wordwrap($email_msg, 70);\n        \n        \/\/ Uncomment the next if statement to set a threshold \n        \/\/ ($value1 = temperature, $value2 = humidity, $value3 = pressure)\n        \/*if($value1 &lt; 24.0){\n            echo &quot;Temperature below threshold, don't send email&quot;;\n            exit;\n        }*\/\n        \n        \/\/ send email with mail(receiver email address, email subject, email message)\n        mail($email_address, &quot;[NEW] ESP BME280 Readings&quot;, $email_msg);\n        \n        echo &quot;Email sent&quot;;\n    }\n    else {\n        echo &quot;Wrong API Key provided.&quot;;\n    }\n\n}\nelse {\n    echo &quot;No data posted with HTTP POST.&quot;;\n}\n\nfunction test_input($data) {\n    $data = trim($data);\n    $data = stripslashes($data);\n    $data = htmlspecialchars($data);\n    return $data;\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP\/ESP_Send_Email\/email-notification.php\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Before saving the file, you need to modify the <span class=\"rnthl rntliteral\">$email_address<\/span> variable with the receiver email address:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Receiver Email Address (where to send email notification)\n$email_address = \"YourEmailAddress@example.com\";<\/code><\/pre>\n\n\n\n<p>After adding the receiver email, save the file and continue with this tutorial. If you try to access your domain name in the next URL path, you&#8217;ll see the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;example.com\/email-notification.php<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"687\" height=\"284\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-ESP8266-Send-Email-PHP-Script-Test.png?resize=687%2C284&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Test Email Notification PHP URL\" class=\"wp-image-90028\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-ESP8266-Send-Email-PHP-Script-Test.png?w=687&amp;quality=100&amp;strip=all&amp;ssl=1 687w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-ESP8266-Send-Email-PHP-Script-Test.png?resize=300%2C124&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 687px) 100vw, 687px\" \/><\/figure><\/div>\n\n\n<p>If you see that message, it means that everything is being setup properly. You can continue with this project.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"set-up-esp32-esp8266\">3. Setting Up Your ESP32 or ESP8266<\/h2>\n\n\n\n<p>This project is compatible with both the ESP32 and ESP8266 boards. You just need to assemble a simple circuit and upload the sketch provided to publish temperature, humidity, and pressure readings to your PHP script, which will then be responsible to handle email notifications. The sketch is slightly different for each board.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>For this example, we&#8217;ll get sensor readings from the BME280 sensor. Here&#8217;s a list of parts you need to build the circuit for this project:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\">ESP32 board<\/a>&nbsp;(read <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\">Best ESP32 dev boards<\/a>)<\/li>\n\n\n\n<li>Alternative &#8211; <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\">ESP8266<\/a> board (read <a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/best-esp8266-wi-fi-development-board\/\" target=\"_blank\">Best ESP8266 dev boards<\/a>)<\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\">BME280 sensor<\/a><\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\">Jumper wires<\/a><\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\">Breadboard<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematics<\/h3>\n\n\n\n<p>The BME280 sensor module we\u2019re using communicates via I2C communication protocol, so you need to connect it to the ESP32 or ESP8266 I2C pins.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">BME280 wiring to ESP32<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td>SCK (SCL Pin)<\/td><td> <span class=\"rnthl rntcblue\">GPIO 22<\/span><\/td><\/tr><tr><td>SDI (SDA pin) <\/td><td> <span class=\"rnthl rntcgreen\">GPIO 21<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>So, assemble your circuit as shown in the next schematic diagram (<a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">read the complete Guide for ESP32 with BME280<\/a>).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"652\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ESP32-bme280_bb.png?resize=750%2C652&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BME280 wiring to ESP32\" class=\"wp-image-56623\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ESP32-bme280_bb.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ESP32-bme280_bb.png?resize=300%2C261&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\"><strong>Recommended reading:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/esp32-pinout-reference-gpios\/\">ESP32 Pinout Reference Guide<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">BME280 wiring to ESP8266<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BME280<\/strong><\/td><td><strong>ESP8266<\/strong><\/td><\/tr><tr><td>SCK (SCL Pin)<\/td><td> <span class=\"rnthl rntcyellow\">GPIO 5<\/span><\/td><\/tr><tr><td>SDI (SDA pin) <\/td><td> <span class=\"rnthl rntclgray\">GPIO 4<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Assemble your circuit as in the next schematic diagram if you&#8217;re using an ESP8266 board (<a href=\"https:\/\/randomnerdtutorials.com\/esp8266-bme280-arduino-ide\/\">read the complete Guide for ESP8266 with BME280<\/a>).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"532\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP8266-BME280-Arduino-IDE.png?resize=705%2C532&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BME280 wiring to ESP8266\" class=\"wp-image-85980\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP8266-BME280-Arduino-IDE.png?w=705&amp;quality=100&amp;strip=all&amp;ssl=1 705w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP8266-BME280-Arduino-IDE.png?resize=300%2C226&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\"><strong>Recommended reading:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-pinout-reference-gpios\/\">ESP8266 Pinout Reference Guide<\/a> <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Libraries<\/h3>\n\n\n\n<p>We\u2019ll program the ESP32\/ESP8266 using Arduino IDE, so you must have the ESP32\/ESP8266 add-on installed in your Arduino IDE. Follow one of the next tutorials depending on the board you&#8217;re using:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/installing-the-esp32-board-in-arduino-ide-windows-instructions\/\">Install the ESP32 Board in Arduino IDE<\/a> &#8211; you also need to <a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">install the BME280 Library <\/a>and <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\">Adafruit_Sensor library<\/a><\/li>\n\n\n\n<li><a style=\"font-size: inherit; background-color: initial;\" href=\"https:\/\/randomnerdtutorials.com\/how-to-install-esp8266-board-arduino-ide\/\">Install the ESP8266 Board in Arduino IDE<\/a> &#8211; you also need to <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-bme280-arduino-ide\/\">install the BME280 Library <\/a>and <a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\">Adafruit_Sensor library<\/a> <\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">ESP32 Code<\/h3>\n\n\n\n<p>Follow this section if you\u2019re using an ESP32.\u00a0<a href=\"#esp8266-code\" title=\"\">For an ESP8266 click here<\/a>.<\/p>\n\n\n\n<p>After installing the necessary board add-ons, copy the following code to your Arduino IDE, but don\u2019t upload it yet. You need to make some changes to make it work for you.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\r\n  Rui Santos\r\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-esp8266-send-email-notification\/\r\n  \r\n  Permission is hereby granted, free of charge, to any person obtaining a copy\r\n  of this software and associated documentation files.\r\n  \r\n  The above copyright notice and this permission notice shall be included in all\r\n  copies or substantial portions of the Software.\r\n\r\n*\/\r\n\r\n#include &lt;WiFi.h&gt;\r\n#include &lt;WiFiClientSecure.h&gt;\r\n#include &lt;HTTPClient.h&gt;\r\n#include &lt;Wire.h&gt;\r\n#include &lt;Adafruit_Sensor.h&gt;\r\n#include &lt;Adafruit_BME280.h&gt;\r\n\r\n\/\/ Replace with your network credentials\r\nconst char* ssid     = &quot;REPLACE_WITH_YOUR_SSID&quot;;\r\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\r\n\r\n\/\/ REPLACE with your Domain name and URL path or IP address with path\r\nconst char* serverName = &quot;https:\/\/example.com\/email-notification.php&quot;;\r\n\r\n\/\/ Keep this API Key value to be compatible with the PHP code provided in the project page. \r\n\/\/ If you change the apiKeyValue value, the PHP file \/email-notification.php also needs to have the same key \r\nString apiKeyValue = &quot;tPmAT5Ab3j7F9&quot;;\r\n\r\n\r\n\/*#include &lt;SPI.h&gt;\r\n#define BME_SCK 18\r\n#define BME_MISO 19\r\n#define BME_MOSI 23\r\n#define BME_CS 5*\/\r\n\r\n#define SEALEVELPRESSURE_HPA (1013.25)\r\n\r\nAdafruit_BME280 bme;  \/\/ I2C\r\n\/\/Adafruit_BME280 bme(BME_CS);  \/\/ hardware SPI\r\n\/\/Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);  \/\/ software SPI\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  \r\n  WiFi.begin(ssid, password);\r\n  Serial.println(&quot;Connecting&quot;);\r\n  while(WiFi.status() != WL_CONNECTED) { \r\n    delay(500);\r\n    Serial.print(&quot;.&quot;);\r\n  }\r\n  Serial.println(&quot;&quot;);\r\n  Serial.print(&quot;Connected to WiFi network with IP Address: &quot;);\r\n  Serial.println(WiFi.localIP());\r\n\r\n  \/\/ (you can also pass in a Wire library object like &amp;Wire2)\r\n  bool status = bme.begin(0x76);\r\n  if (!status) {\r\n    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring or change I2C address!&quot;);\r\n    while (1);\r\n  }\r\n  \/\/Check WiFi connection status\r\n  if(WiFi.status()== WL_CONNECTED){\r\n    WiFiClientSecure *client = new WiFiClientSecure;\r\n    client-&gt;setInsecure(); \/\/don't use SSL certificate\r\n    HTTPClient https;\r\n    \r\n    \/\/ Your Domain name with URL path or IP address with path\r\n    https.begin(*client, serverName);\r\n    \r\n    \/\/ Specify content-type header\r\n    https.addHeader(&quot;Content-Type&quot;, &quot;application\/x-www-form-urlencoded&quot;);\r\n    \r\n    \/\/ Prepare your HTTP POST request data\r\n\r\n    String httpRequestData = &quot;api_key=&quot; + apiKeyValue + &quot;&amp;value1=&quot; + String(bme.readTemperature())\r\n                           + &quot;&amp;value2=&quot; + String(bme.readHumidity()) + &quot;&amp;value3=&quot; + String(bme.readPressure()\/100.0F) + &quot;&quot;;\r\n   \r\n    Serial.print(&quot;httpRequestData: &quot;);\r\n    Serial.println(httpRequestData);\r\n    \r\n    \/\/ You can comment the httpRequestData variable above\r\n    \/\/ then, use the httpRequestData variable below (for testing purposes without the BME280 sensor)\r\n    \/\/String httpRequestData = &quot;api_key=tPmAT5Ab3j7F9&amp;sensor=BME280&amp;location=Office&amp;value1=24.75&amp;value2=49.54&amp;value3=1005.14&quot;;\r\n\r\n    \/\/ Send HTTP POST request\r\n    int httpResponseCode = https.POST(httpRequestData);\r\n     \r\n    \/\/ If you need an HTTP request with a content type: text\/plain\r\n    \/\/https.addHeader(&quot;Content-Type&quot;, &quot;text\/plain&quot;);\r\n    \/\/int httpResponseCode = https.POST(&quot;Hello, World!&quot;);\r\n    \r\n    \/\/ If you need an HTTP request with a content type: application\/json, use the following:\r\n    \/\/https.addHeader(&quot;Content-Type&quot;, &quot;application\/json&quot;);\r\n    \/\/int httpResponseCode = https.POST(&quot;{\\&quot;value1\\&quot;:\\&quot;19\\&quot;,\\&quot;value2\\&quot;:\\&quot;67\\&quot;,\\&quot;value3\\&quot;:\\&quot;78\\&quot;}&quot;);\r\n    \r\n    if (httpResponseCode&gt;0) {\r\n      Serial.print(&quot;HTTP Response code: &quot;);\r\n      Serial.println(httpResponseCode);\r\n    }\r\n    else {\r\n      Serial.print(&quot;Error code: &quot;);\r\n      Serial.println(httpResponseCode);\r\n    }\r\n    \/\/ Free resources\r\n    https.end();\r\n  }\r\n  else {\r\n    Serial.println(&quot;WiFi Disconnected&quot;);\r\n  } \r\n  \/\/ Use deep sleep to make the ESP send an email every X number of minutes\/hours with low power consumption\r\n  \/\/ ESP32 Deep Sleep Guide: https:\/\/RandomNerdTutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/  \r\n}\r\n\r\nvoid loop() {\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/HTTPS_ESP32_Send_Email_PHP.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Setting your network credentials<\/h4>\n\n\n\n<p>You need to modify the following lines with your network credentials: SSID and password. The code is well commented on where you should make the changes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Replace with your network credentials\nconst char* ssid     = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Setting your serverName<\/h4>\n\n\n\n<p>You also need to type your domain name, so the ESP publishes the readings to your own server.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* serverName = \"https:\/\/example.com\/email-notification.php\";<\/code><\/pre>\n\n\n\n<p>Now, you can upload the code to your board.<\/p>\n\n\n\n<p><strong>Note:&nbsp;<\/strong>Most servers require you to make HTTPS requests. The code above makes HTTPS requests to be compliant with the requirements of most cloud servers nowadays.<\/p>\n\n\n\n<p class=\"rntbox rntclgray\">Your server doesn\u2019t support HTTPS?\u00a0<a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/master\/Projects\/ESP\/ESP_Send_Email\/ESP_Send_Email.ino\" target=\"_blank\" rel=\"noopener\" title=\"\">Use this code instead<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How the code works<\/h4>\n\n\n\n<p>Here&#8217;s a quick summary of how the code works:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Import all the libraries to make it work (it will import either the ESP32 or ESP8266 libraries based on the selected board in your Arduino IDE);<\/li>\n\n\n\n<li>Set variables that you might want to change (<span class=\"rnthl rntliteral\">apiKeyValue<\/span>);<\/li>\n\n\n\n<li>The <span class=\"rnthl rntliteral\">apiKeyValue<\/span> is just a random string that you can modify. It&#8217;s used for security reasons, so only anyone that knows your API key can send email notifications.<\/li>\n\n\n\n<li>Initialize the serial communication for debugging purposes;<\/li>\n\n\n\n<li>Establish a Wi-Fi connection with your router;<\/li>\n\n\n\n<li>Initialize the BME280 sensor to get temperature, humidity, and pressure readings;<\/li>\n\n\n\n<li>Initialize a secure WiFi client.<\/li>\n<\/ul>\n\n\n\n<p>Then, in the rest of the <span class=\"rnthl rntliteral\">setup()<\/span> is where you actually make the HTTP POST with the latest BME280 readings:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Your Domain name with URL path or IP address with path\nhttp.begin(client, serverName);\n\n\/\/ Specify content-type header\nhttp.addHeader(\"Content-Type\", \"application\/x-www-form-urlencoded\");\n\n\/\/ Prepare your HTTP POST request data\nString httpRequestData = \"api_key=\" + apiKeyValue + \"&amp;value1=\" + String(bme.readTemperature())\n                       + \"&amp;value2=\" + String(bme.readHumidity()) + \"&amp;value3=\" + String(bme.readPressure()\/100.0F) + \"\";\n\nint httpResponseCode = http.POST(httpRequestData);<\/code><\/pre>\n\n\n\n<p>You can comment the <span class=\"rnthl rntliteral\">httpRequestData<\/span> variable above that concatenates all the BME280 readings and use the <span class=\"rnthl rntliteral\">httpRequestData<\/span> variable below for testing purposes:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String httpRequestData = \"api_key=tPmAT5Ab3j7F9&amp;value1=24.75&amp;value2=49.54&amp;value3=1005.14\";<\/code><\/pre>\n\n\n\n<p class=\"rntbox rntclblue\">Learn more about HTTPS Requests with the ESP32:&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/esp32-https-requests\/\">ESP32 HTTPS Requests (Arduino IDE)<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"esp8266-code\">ESP8266 Code<\/h3>\n\n\n\n<p>Follow this section if you\u2019re using an ESP8266.\u00a0<a href=\"#esp32-code\" title=\"\">For an ESP32 check the section above<\/a>.<\/p>\n\n\n\n<p>After installing the necessary board add-ons, copy the following code to your Arduino IDE, but don\u2019t upload it yet. You need to make some changes to make it work for you.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\r\n  Rui Santos\r\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-esp8266-send-email-notification\/\r\n  \r\n  Permission is hereby granted, free of charge, to any person obtaining a copy\r\n  of this software and associated documentation files.\r\n  \r\n  The above copyright notice and this permission notice shall be included in all\r\n  copies or substantial portions of the Software.\r\n\r\n*\/\r\n\r\n#include &lt;ESP8266WiFi.h&gt;\r\n#include &lt;ESP8266HTTPClient.h&gt;\r\n#include &lt;WiFiClientSecureBearSSL.h&gt;\r\n#include &lt;Wire.h&gt;\r\n#include &lt;Adafruit_Sensor.h&gt;\r\n#include &lt;Adafruit_BME280.h&gt;\r\n\r\n\/\/ Replace with your network credentials\r\nconst char* ssid     = &quot;REPLACE_WITH_YOUR_SSID&quot;;\r\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\r\n\r\n\/\/ REPLACE with your Domain name and URL path or IP address with path\r\nconst char* serverName = &quot;https:\/\/example.com\/email-notification.php&quot;;\r\n\r\n\/\/ Keep this API Key value to be compatible with the PHP code provided in the project page. \r\n\/\/ If you change the apiKeyValue value, the PHP file \/email-notification.php also needs to have the same key \r\nString apiKeyValue = &quot;tPmAT5Ab3j7F9&quot;;\r\n\r\n\/*#include &lt;SPI.h&gt;\r\n#define BME_SCK 18\r\n#define BME_MISO 19\r\n#define BME_MOSI 23\r\n#define BME_CS 5*\/\r\n\r\n#define SEALEVELPRESSURE_HPA (1013.25)\r\n\r\nAdafruit_BME280 bme;  \/\/ I2C\r\n\/\/Adafruit_BME280 bme(BME_CS);  \/\/ hardware SPI\r\n\/\/Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);  \/\/ software SPI\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  \r\n  WiFi.begin(ssid, password);\r\n  Serial.println(&quot;Connecting&quot;);\r\n  while(WiFi.status() != WL_CONNECTED) { \r\n    delay(500);\r\n    Serial.print(&quot;.&quot;);\r\n  }\r\n  Serial.println(&quot;&quot;);\r\n  Serial.print(&quot;Connected to WiFi network with IP Address: &quot;);\r\n  Serial.println(WiFi.localIP());\r\n\r\n  \/\/ (you can also pass in a Wire library object like &amp;Wire2)\r\n  bool status = bme.begin(0x76);\r\n  if (!status) {\r\n    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring or change I2C address!&quot;);\r\n    while (1);\r\n  }\r\n  \/\/Check WiFi connection status\r\n  if(WiFi.status()== WL_CONNECTED){\r\n\r\n    std::unique_ptr&lt;BearSSL::WiFiClientSecure&gt;client(new BearSSL::WiFiClientSecure);\r\n\r\n    \/\/ Ignore SSL certificate validation\r\n    client-&gt;setInsecure();\r\n    \r\n    \/\/create an HTTPClient instance\r\n    HTTPClient https;\r\n    \r\n    \/\/ Your Domain name with URL path or IP address with path\r\n    https.begin(*client, serverName);\r\n    \r\n    \/\/ Specify content-type header\r\n    https.addHeader(&quot;Content-Type&quot;, &quot;application\/x-www-form-urlencoded&quot;);\r\n    \r\n    \/\/ Prepare your HTTP POST request data\r\n    String httpRequestData = &quot;api_key=&quot; + apiKeyValue + &quot;&amp;value1=&quot; + String(bme.readTemperature())\r\n                           + &quot;&amp;value2=&quot; + String(bme.readHumidity()) + &quot;&amp;value3=&quot; + String(bme.readPressure()\/100.0F) + &quot;&quot;;\r\n    Serial.print(&quot;httpRequestData: &quot;);\r\n    Serial.println(httpRequestData);\r\n    \r\n    \/\/ You can comment the httpRequestData variable above\r\n    \/\/ then, use the httpRequestData variable below (for testing purposes without the BME280 sensor)\r\n    \/\/String httpRequestData = &quot;api_key=tPmAT5Ab3j7F9&amp;sensor=BME280&amp;location=Office&amp;value1=24.75&amp;value2=49.54&amp;value3=1005.14&quot;;\r\n\r\n    \/\/ Send HTTP POST request\r\n    int httpResponseCode = https.POST(httpRequestData);\r\n     \r\n    \/\/ If you need an HTTP request with a content type: text\/plain\r\n    \/\/http.addHeader(&quot;Content-Type&quot;, &quot;text\/plain&quot;);\r\n    \/\/int httpResponseCode = https.POST(&quot;Hello, World!&quot;);\r\n    \r\n    \/\/ If you need an HTTP request with a content type: application\/json, use the following:\r\n    \/\/http.addHeader(&quot;Content-Type&quot;, &quot;application\/json&quot;);\r\n    \/\/int httpResponseCode = https.POST(&quot;{\\&quot;value1\\&quot;:\\&quot;19\\&quot;,\\&quot;value2\\&quot;:\\&quot;67\\&quot;,\\&quot;value3\\&quot;:\\&quot;78\\&quot;}&quot;);\r\n        \r\n    if (httpResponseCode&gt;0) {\r\n      Serial.print(&quot;HTTP Response code: &quot;);\r\n      Serial.println(httpResponseCode);\r\n    }\r\n    else {\r\n      Serial.print(&quot;Error code: &quot;);\r\n      Serial.println(httpResponseCode);\r\n    }\r\n    \/\/ Free resources\r\n    https.end();\r\n  }\r\n  else {\r\n    Serial.println(&quot;WiFi Disconnected&quot;);\r\n  }\r\n  \/\/ Use deep sleep to make the ESP send an email every X number of minutes\/hours with low power consumption\r\n  \/\/ ESP8266 Deep Sleep Guide: https:\/\/RandomNerdTutorials.com\/esp8266-deep-sleep-with-arduino-ide\/\r\n}\r\n\r\nvoid loop() {\r\n\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/HTTPS_ESP8266_Send_Email_PHP.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Setting your network credentials<\/h4>\n\n\n\n<p>You need to modify the following lines with your network credentials: SSID and password. The code is well commented on where you should make the changes.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Replace with your network credentials\nconst char* ssid     = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Setting your serverName<\/h4>\n\n\n\n<p>You also need to type your domain name, so the ESP publishes the readings to your own server.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* serverName = \"https:\/\/example.com\/email-notification.php\";<\/code><\/pre>\n\n\n\n<p>Now, you can upload the code to your board.<\/p>\n\n\n\n<p><strong>Note:&nbsp;<\/strong>Most servers require you to make HTTPS requests. The code above makes HTTPS requests to be compliant with the requirements of most cloud servers nowadays.<\/p>\n\n\n\n<p class=\"rntbox rntclgray\">Your server doesn\u2019t support HTTPS?\u00a0<a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/master\/Projects\/ESP\/ESP_Send_Email\/ESP_Send_Email.ino\" target=\"_blank\" rel=\"noopener\" title=\"\">Use this code instead<\/a>.<\/p>\n\n\n\n<p class=\"rntbox rntclblue\">Learn more about HTTPS Requests with the ESP8266:\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-https-requests\/\">ESP8266 NodeMCU HTTPS Requests (Arduino IDE)<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>After completing all the steps, power your ESP board and let it make an HTTP request to your server:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-BME280-Arduino-IDE-MySQL.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 BME280 Arduino IDE MySQL\" class=\"wp-image-86000\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-BME280-Arduino-IDE-MySQL.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/06\/ESP32-BME280-Arduino-IDE-MySQL.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>If everything is working properly, this is what you should see in your Arduino IDE Serial Monitor:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"493\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-ESP8266-Send-Email-Arduino-IDE-Serial-Monitor.png?resize=873%2C493&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Send Email Arduino IDE Serial Monitor\" class=\"wp-image-90032\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-ESP8266-Send-Email-Arduino-IDE-Serial-Monitor.png?w=873&amp;quality=100&amp;strip=all&amp;ssl=1 873w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-ESP8266-Send-Email-Arduino-IDE-Serial-Monitor.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/ESP32-ESP8266-Send-Email-Arduino-IDE-Serial-Monitor.png?resize=768%2C434&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 873px) 100vw, 873px\" \/><\/figure><\/div>\n\n\n<p>Open your email client, you should have a new email with the subject &#8220;<strong>[NEW] ESP BME280 Readings<\/strong>&#8221; with the latest temperature readings:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"489\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/03\/Sensor-Readings-Email-PHP-ESP32-ESP8266-f.png?resize=250%2C489&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Send Email Notification using PHP temperature humidity pressure\" class=\"wp-image-129644\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/03\/Sensor-Readings-Email-PHP-ESP32-ESP8266-f.png?w=250&amp;quality=100&amp;strip=all&amp;ssl=1 250w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/03\/Sensor-Readings-Email-PHP-ESP32-ESP8266-f.png?resize=153%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 153w\" sizes=\"(max-width: 250px) 100vw, 250px\" \/><\/figure><\/div>\n\n\n<p>To send a new email, press the ESP on-board RESET\/ENABLE button to restart it and new readings will be sent out via email.<\/p>\n\n\n\n<p>For a final application, I recommend using deep sleep to make the ESP send an email every X number of minutes\/hours with low power consumption. Read one of these guides to add deep sleep to your sketch:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/\">ESP32 Deep Sleep with Arduino IDE and Wake Up Sources<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-deep-sleep-with-arduino-ide\/\">ESP8266 Deep Sleep with Arduino IDE<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Enable Threshold Notification<\/h2>\n\n\n\n<p>Finally, keep in mind that every time you restart your ESP (or the ESP wakes from deep sleep), it will send a new email notification with the current values. It might be useful to set a threshold value so that you only receive an email notification when your readings are above or below the threshold.<\/p>\n\n\n\n<p>In your PHP script (<em>email-notification.php<\/em>), uncomment the following if statement:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Uncomment the next if statement to set a threshold \n\/\/ ($value1 = temperature, $value2 = humidity, $value3 = pressure)\n\/*if($value1 &lt; 24.0){\n    echo \"Temperature below threshold, don't send email\";\n    exit;\n}*\/<\/code><\/pre>\n\n\n\n<p>It will look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Uncomment the next if statement to set a threshold \n\/\/ ($value1 = temperature, $value2 = humidity, $value3 = pressure)\nif($value1 &lt; 24.0){\n    echo \"Temperature below threshold, don't send email\";\n    exit;\n}<\/code><\/pre>\n\n\n\n<p>You can modify that if statement with the value threshold and only send an email based on that condition. With the current code, it will only send an email notification when the temperature is above 24.0\u00baC.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial you&#8217;ve learned how to send emails with the ESP32 and ESP8266 using your own <a rel=\"noreferrer noopener\" aria-label=\"server and domain name (opens in a new tab)\" href=\"https:\/\/randomnerdtutorials.com\/bluehost\" target=\"_blank\">server and domain name<\/a>. <\/p>\n\n\n\n<p>The example provided is as simple as possible so that you can understand how everything works. After understanding this example, you may change the email content, publish different sensor readings, use multiple ESP boards, and much more.<\/p>\n\n\n\n<p><strong>You might also like reading:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-mysql-database-php\/\">ESP32\/ESP8266 Insert Data into MySQL Database using PHP and Arduino IDE<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/visualize-esp32-esp8266-sensor-readings-from-anywhere\/\">Visualize Your Sensor Readings from Anywhere in the World<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/\">ESP32 Deep Sleep with Arduino IDE and Wake Up Sources<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-deep-sleep-with-arduino-ide\/\">ESP8266 Deep Sleep with Arduino IDE<\/a><\/li>\n<\/ul>\n\n\n\n<p>Learn more about the ESP32 with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build Web Servers with ESP32 and ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/firebase-esp32-esp8266-ebook\/\">Firebase Web App with ESP32 and ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/smart-home-ebook\/\">SMART HOME with Raspberry Pi, ESP32, and ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">Free ESP32 Projects and Tutorials\u2026<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thank you for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project, you\u2019ll build an ESP32 or ESP8266 client that makes an HTTP POST request to a PHP script to send an email notification with sensor readings. Updated on &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32\/ESP8266 Send Email Notification using PHP Script\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-send-email-notification\/#more-90022\" aria-label=\"Read more about ESP32\/ESP8266 Send Email Notification using PHP Script\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":129640,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[281,276,277,299,264],"tags":[],"class_list":["post-90022","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/10\/Send-Email-ESP32-ESP8266-PHP-Script.png?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/90022","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=90022"}],"version-history":[{"count":6,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/90022\/revisions"}],"predecessor-version":[{"id":129646,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/90022\/revisions\/129646"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/129640"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=90022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=90022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=90022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}