Free Sending Emails with PHP

Email has become one of the integral part of our daily process in recent years. Especially to business or corporate houses, emails are widely used for communication and marketing purposes.

In this article, we are going to learn to send emails using PHP. We will be using the service of Sendinblue API to send email. We are provided with 300 emails quota per day in free plan.

First, we need to register an account in https://www.sendinblue.com/ and get an API key.

1. Download Mailin.php library

Import Mailin.php from here https://github.com/mailin-api/mailin-api-php/blob/master/src/Sendinblue/Mailin.php

2. Source Code for index.php

<?php

include('Mailin.php');
use Sendinblue\Mailin;
$api_key = '**********';

$from_email = '*****@gmail.com';
$from_name = 'Name of Sender';

$to_email = '******@gmail.com';
$to_name = 'Name of Receiver';
$subject = 'This is the subject';
$message = '<h2>Heading 2</h2><p>Here goes the paragraph blah blah blah</p>';

$mailin = new Mailin('https://api.sendinblue.com/v2.0',$api_key);
$data = array( 
  "to" => array($to_email=>$to_name),
  "from" => array($from_email,$from_name),
  "subject" => $subject,
  "html" => $message,
  "attachment" => array()
);

$response = $mailin->send_email($data);
if(isset($response['code']) && $response['code']=='success'){
  echo 'Email Sent';
}else{
  echo 'Email not sent';
}
exit;

 

Follow this video for complete guidance :

Recommended For You

About the Author: Ritesh Ghimire

Ritesh is a Computer Engineer, Web Developer and an active cricket follower.