This library can be used in your PHP script to send the emails using MAILIN-SMTP Services.
(c) 2013 Mailin
Download the Mailin SMTP Library “Mailin.php” from
https://github.com/DTSL/mailin-smtp-api.git
Include the "Mailin.php" file that you have downloaded.
<?php
include 'path/to/mailin-api/Mailin.php';
?>
Initialized the Mailin object with your Mailin SMTP credentials. Credentials can be found at http://mysmtp.mailin.fr/parameters
<?php
$mailin = new Mailin('username', 'password');
?>
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"))
*/
?>
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.
*/
?>
Below is a list of common Mailin 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 mailinblue.com.