1. Go to this page and download the library: Download freshmail/php-api-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
freshmail / php-api-client example snippets
use \FreshMail\Api\Client\Service\Messaging\Mail;
use \FreshMail\Api\Client\Messaging\Mail\MailBag;
$token = 'MY_APP_TOKEN';
$mailService = new Mail($token);
$mail = new MailBag();
$mail->setFrom('[email protected]', 'Office');
$mail->setSubject('That\'s my awesome first mail!');
$mail->setHtml('<html><body><strong>Look!</strong> its working!</body></html>');
$mail->addRecipientTo('recipient email address');
$response = $mailService->send($mail);
if ($response->isSuccess()) {
$responseData = $response->getData();
}
$response->getPsr7Response();
use \FreshMail\Api\Client\Service\Messaging\Mail;
use \FreshMail\Api\Client\Messaging\Mail\MailBag;
$token = 'MY_APP_TOKEN';
$mailService = new Mail($token);
$mail = new MailBag();
$mail->setFrom('[email protected]', 'Office');
$mail->setSubject('Hello $$first_name$$! I\'v got promotion code for You!');
$mail->setHtml('<html><body>Your code is <strong>$$code$$</strong></body></html>');
$mail->addRecipientTo('recipient email address', [
'first_name' => 'Joshua',
'code' => 'CODE1234'
]);
$response = $mailService->send($mail);
use \FreshMail\Api\Client\Service\Messaging\Mail;
use \FreshMail\Api\Client\Messaging\Mail\MailBag;
$token = 'MY_APP_TOKEN';
$mailService = new Mail($token);
$mail = new MailBag();
$mail->setFrom('[email protected]', 'Support');
$mail->setSubject('Hello, that\'s my email genereted by template!');
$mail->setTemplateHash('TEMPLATE_HASH');
$mail->addRecipientTo('recipient email address');
$response = $mailService->send($mail);
use \FreshMail\Api\Client\Service\Messaging\Mail;
use \FreshMail\Api\Client\Messaging\Mail\Base64Attachment;
use \FreshMail\Api\Client\Messaging\Mail\LocalFileAttachment;
use \FreshMail\Api\Client\Messaging\Mail\MailBag;
$token = 'MY_APP_TOKEN';
$mailService = new Mail($token);
//attachment from hard drive
$localFileAttachment = new LocalFileAttachment(
'/my/local/path/file.extension',
'optional file name'
);
//attachment from base64
$base64Attachment = new Base64Attachment(
'example.txt',
base64_encode('example content')
);
$mail = new MailBag();
$mail->setFrom('[email protected]', 'Support');
$mail->setSubject('Hello, thats mail with attachments!!');
$mail->setHtml('<html><body><strong>Attachments</strong> in mail</body></html>');
$mail->addRecipientTo('recipient email address');
$mail->addAttachment($localFileAttachment);
$mail->addAttachment($base64Attachment);
$response = $mailService->send($mail);