Git Product home page Git Product logo

mailin-smtp-api's Introduction

DEPRECATED: SendinBlue SMTP Library 1.0

Note:

The library is now maintained at https://github.com/mailin-api/

The latest Documentation for transactional emails is available here https://apidocs.sendinblue.com/tutorial-sending-transactional-email/

This library can be used in your PHP script to send the emails using SENDINBLUE-SMTP Services.

(c) 2014 SendinBlue


How To Install The SendinBlue SMTP Library

Step 1:

Download the SendinBlue SMTP Library “Mailin.php” from https://github.com/DTSL/mailin-smtp-api.git

Step 2:

Include the "Mailin.php" file that you have downloaded.

<?php
include 'path/to/mailin-api/Mailin.php';
?>

Step 3:

Initialized the Mailin object with your SendinBlue SMTP credentials. Credentials can be found at http://mysmtp.sendinblue.com/parameters

<?php
$mailin = new Mailin('username', 'password');
?>

Step 4:

With the help of Mailin object create your email message:

<?php
$mailin->
  addTo('[email protected]', 'Foo')-> 

  addCc('[email protected]','example cc')-> 

  addBcc('[email protected]','example bcc')->

/**
If you need to send the email to more than 1 recipient, you can add them in an array format.
    addTo(
        array(
            '[email protected]' => 'example one',
            '[email protected]' => 'example two'
   )
    )->

Similarly an array can be created to send multiple carbon copy recipients.
    addCc(
        array(
            '[email protected]' => 'example one',
            '[email protected]' => 'example two'
	 )
    )->

Again for multiple blind carbon copy recipients we can use array.
    addBcc(
        array(
            '[email protected]' => 'example one',
            '[email protected]' => 'example two'
	 )
    )->
    
If you want to add tag in mail headers, you can add as
    addHeader('X-Mailin-tag' , 'xyz')->
    
If you want to add IP in mail headers, you can add as
    addHeader('X-Mailin-IP' , 'x.x.x.x')->    

*/

  setFrom('[email protected]', 'mailin')->
  setReplyTo('[email protected]','reply name')->
  setSubject('Subject goes here')->
  setText('Hello World!')->
  setHtml('<strong>Hello World!</strong>')->
  addAttachment("path/foo.txt")->

/**
   If you wan to attach multiple attachments, you can use an array with the addAttachment function. For example:
addAttachment(array("path/filename1.txt","path/filename2.txt"))

*/

/**

#### How to send attachment/s generated on the fly ####

If you want to send attachment/s generated on the fly you have to pass your attachment/s filename & its base64 encoded chunk data in key-value pair in an array with createAttachment function. For example:

createAttachment(array(“YourFileName1.Extension” => “Base64EncodedChunkData1″, “YourFileName2.Extension” => “Base64EncodedChunkData2″))

Below, sample code using [html2pdf](http://html2pdf.fr) function (You can send other kind of files but for our example, we choose to send a pdf file)

**NOTE:** Please add line of codes between commented area from start & end of pdf creation before Step 4.

*/
  
// Start pdf creation
require_once('html2pdf/html2pdf.class.php'); // link to html2pdf file
$content = "<h1>My PDF header</h1><br>This is my PDF content<br>";
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($content);
$contentPdf = $html2pdf->Output('', true);
$attachment_content = chunk_split(base64_encode($contentPdf));
// End pdf creation

createAttachment(array('example.pdf'=>$attachment_content));

?>

Step 5:

Now call the send function using the Mailin object:

<?php

$res = $mailin->send();

/**
The return format is JSON.


Successful email sent message will be returned as:
{'result' => true, 'message' => 'Email sent successfully.'}

In case of unsuccessful email sent, the result will be false with the appropriate failure message.

*/
?>

Error Codes

Below is a list of common SendinBlue SMTP error codes and their meanings.

Error Code: 421
Error Description: Unable to send email. Exception message was:  Hourly Quota Exceeded.

Error Code: 550
Error Description: The size of your file should not be greater than 10 Mb.

Error Code: 902
Error Description: Unable to send email. Exception message was:  Account Terminated.

Error Code: 903
Error Description: Unable to send email. Exception message was: The parameters you passed are not well formated. Please refer to https://github.com/DTSL/mailin-smtp-api or contact us at contact at sendinblue.com.

mailin-smtp-api's People

Contributors

shouvik-slit avatar ekta-slit avatar armandth avatar

Watchers

Erwan. avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.