Choose Language

Sending Mails with Other Popular Libraries

Info! This is Beta version, if you have any problem in using API, please mail us at [email protected]

PHP CodeIgniter

You can use this library to send email using CodeIgniter. Download it from here and unzip to any folder. Place our libraries folder to your CodeIgniter application folder and use it as below.

Example Controller

class EmailTest extends CI_Controller {
    public function index() {
        echo 'Hello From Test!';
    public function sendMail() {
        $owner_id = 'owner_id';
        $apiToken = 'token';
        $smtp_user_name = "smtp12345";
        $this->sarv->init($owner_id, $apiToken, $SarvTES_APP_DOMAIN); //You must call this method once before any other method call
        $recipients = array(
                'email' => '[email protected]',
                'name' => 'Recipient1 Name'
                'email' => '[email protected]',
                'name' => 'Recipient2 Name'
        foreach ($recipients as $recipient) {
            $message = array();
            $message["html"] = "Example HTML content";
            $message["text"] = "Example text content";
            $message["subject"] = "example subject";
            $message["from_email"] = "[email protected]";
            $message["to"] = array(
                array("email" => $recipient['email'], "name" => $recipient['name'], "type" => "to")
            $message["headers"] = array("Reply-To" => "[email protected]", "X-Unique-Id" => "Id");
            $message["attachments"] = array(array("type" => "text/plain", "name" => "myfile.txt", "content" => "ZXhhbXBsZSBmaWxl"));
            $message["images"] = array(array("type" => "image/png", "name" => "IMAGECID", "content" => "dgfdddger"));
            $result = $this->sarv->messages->sendMail($smtp_user_name, $message);
              [status] => "success"
              [message] => "message have been Queued ... "



A full-featured email creation and transfer class for PHP You can download it from here


   require 'PHPMailerAutoload.php';

    $mail = new PHPMailer;

    //$mail->SMTPDebug = 3;                               // Enable verbose debug output

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = '<SarvTES_APP_DOMAIN>';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '<smtp_user_name>';                 // SMTP username
    $mail->Password = '<smtp_password>';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
    $mail->LE = "\r\n";                                   // For more

    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
    $mail->addAddress('[email protected]');               // Name is optional
    $mail->addReplyTo('[email protected]', 'Information');
    $mail->addCC('[email protected]');
    $mail->addBCC('[email protected]');

    $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->addCustomHeader('X-Unique-Id', 'id');

    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body in bold!';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';


Swift Mailer

Comprehensive mailing tools for PHP. You can download it from here


    require_once '/path/to/swift-mailer/lib/swift_required.php';

    // Create the Transport
    $transport = Swift_SmtpTransport::newInstance('<SarvTES_APP_DOMAIN>', 587)

    // Create the Mailer using your created Transport
    $mailer = Swift_Mailer::newInstance($transport);

    // Create the message
    $message = Swift_Message::newInstance()

    // Give the message a subject
            ->setSubject('Your subject')

    // Set the From address with an associative array
            ->setFrom(array('[email protected]' => 'John Doe'))

    // Set the To addresses with an associative array
            ->setTo(array('[email protected]', '[email protected]' => 'A name'))

    // Give it a body
            ->setBody('Here is the message itself')

    // And optionally an alternative body
            ->addPart('Here is the message itself', 'text/html')

    // Optionally add any attachments

    // Add your custom headers
    $message->getHeaders()->addTextHeader('X-Unique-Id', 'id');

    // Send the message
    $result = $mailer->send($message);