How to Build an Email Subscriber List by using Firebase

How to Build an Email Subscriber List by using Firebase


BUILD AN EMAIL SUBSCRIBER LIST BY USING FIREBASE

In this Tutorial, we are going to see the Method to Build an Email Subscriber List by using Firebase.
Recently, I am Started Working on Google Firebase for adding Some Features on My Android Application.
I made some Experiments on Google Firebase it having a Lot of Features
Personally, I am using Firebase for
  • Personal Contact Storage
  • Important file and Image backups
  • Host the Static sites and Gif Images
  • Web Push Notification
Still, My Experiments are going in between I got this awesome Concept – Build an Email Subscriber List by using Firebase RealTime Database.

FIREBASE EMAIL SUBSCRIPTION WIDGET

it is an Simple Concept Collect your Website/blog readers Email & Names on Firebase real-time Database via HTML Input Form (PHP cURL + POST Method).

METHODS USING

  • Firebase Real-time Database for Collect the user’s data
  • PHP cURL Method – send the user’s data into Firebase Real-time Database
  • JSON and PHP Post Method
Setup and Demo Video

FIREBASE PROJECT SETUP

Build an Email Subscriber List by using Firebase
  • After Opening Database Go to Database RULES
Build an Email Subscriber List by using Firebase
  • Update the Default Database Auth Rules
{
 "rules": {
 ".read": "auth != true",
 ".write": "auth != true"
 }
}
“.read”: “auth != true”, – Read our Data’s in JSON Format – https://example-project.firebaseio.com/subscribers.json if you don’t want replace it with null
“.write”: “auth != true” – Give Permission to write the Data’s it Must be true then only user’s input data are Stored in the Real-time Database.
Build an Email Subscriber List by using Firebase

EMAIL SUBSCRIPTION WIDGET SETUP

  • Create a New Folder on your Web server Named as subscribe
  • Download this Widget From Github

  • Upload this widget on Newly Created Folder – subscribe
  • Visitor’s Subscribe URL – http://example.com/subscribe
  • open index.php
//replace https://example-project.firebaseio.com with Firebase Realtime DB URL - DON'T REMOVE /subscribers.json
$url = "https://example-project.firebaseio.com/subscribers.json";
  • Replace it with your Firebase real-time Database Storage URL
  • That’s all
  • Next, Save the settings and Start Building your Blog/website Email Subscriber List
  • All the Collected Emails & Names are Stored on Firebase Real-time Database
  • You can Export the collected Email’s as JSON Format only – there are plenty of online sites available for converting the JSON into CSV format else you can do it manually
Gist
<?php
class Data {
/**
* Returns a sanatized email;
*
* @param string $data
* @return string
*/
public static function clean_email($data) {
$data = preg_replace("/[^a-zA-Z0-9-@.]/", "", $data);
return $data;
}
/**
* Strip all characters but letters, numbers, and whitespace;
*
* @param string $data
* @return string
*/
public static function clean_name($data) {
$data = preg_replace("/[^a-zA-Z0-9\s]/", "", $data);
return $data;
}
}
view rawdata.php hosted with ❤ by GitHub
<?php
/**
* Firebase Realtime Database Using PHP Curl.
* Collect your Blog/website readers name and email on Firebase Realtime database.
*
* @package Firebase Email Subscription
* @author Santhosh veer
* @license GPL-2.0+
* @link https://www.allwebtuts.com
* @copyright 2016-2018 allwebtuts.com, All rights reserved.
*
* @Firebase Email Subscription
* Plugin Name: Firebase Email Subscription
* Plugin URI: https://www.allwebtuts.com/
* Description: Build your Email List - Collect your Blog Visitor's Email on Firebase realtime Database
* Version: 1.1
* License: GPL-3.0+
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
*/
// data sanitization
require_once dirname(__FILE__) . '/data.php';
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$name= $_POST["name"];
$email= $_POST["email"];
$name = Data::clean_name($name);
$email = Data::clean_email($email);
//$name = htmlspecialchars($name,ENT_COMPAT);
//$email = htmlspecialchars($email,ENT_COMPAT);
$data = '{
"subscriber": {
"name": "' . $name . '","email": "' . $email . '"}
}';
//replace https://example-project.firebaseio.com with Firebase Realtime DB URL - DON'T REMOVE /subscribers.json
$url = "https://example-project.firebaseio.com/subscribers.json";
// cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($ch);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
// Show result on JSON Format - if you don't want this just add // infront of the echo
//echo $response . "\n";
//echo $data . "\n";
}
$message= "Thanks for Subscribe to our Blog Post Updates";
?>
<form method="post">
<input type="text" name="name" required>
<input type="email" name="email" required>
<button type="submit">send</button>
</form>
<br/>
<?php
if(isset($_POST['name'])) {
echo $message;
}
?>
view rawindex.php hosted with ❤ by GitHub

PROS & CONS

PROS

  • Real-time database Storage
  • Easy to Setup
  • $0 Investment

CONS

  • No CSV Export Option
  • 1GB Storage only (If you Want More you need to Upgrade the Plan)

FROM THE EDITOR’S DESK

Hope this method will Help you to Build an Email Subscriber List by using Firebase RealTime Database.
Our Plugin was Hosted on Github If you having Any Concept & ideas for this Firebase Email Subscription Widget then Contribute on Github
If you need any Help in Setup Just drop your Comments Here I will Guide you.

Comments