Send Mail
YeeBase send email using sendMail()
function in yeebase\extensions\ysUtil\ysUtil.php
. This extensions override base on composer package \Exiang\YsUtil\YsUtil
.
Sending using ysUtil::sendMail()
$receivers[] = array('email' => 'receiver@yahoo.com', 'name' => 'Receiver Name');
$subject = 'Try sending email using ysUtil::sendMail function';
$htmlString = '<h2>Lorem ipsum dolor sit amet</h2><p><b>consectetur</b> adipiscing elit:</p><ol><li><a href="http://www.wikipedia.com">Wikipedia</a></li><li>Google</li><li>Yahoo</li></ol>';
// send thru extension `yeebase\extensions\ysUtil`
$result = ysUtil::sendMail($receivers, $subject, $htmlString);
if ($result === true) {
// mail sent successfully
}
Sending using template
Using a template make sure all your outgoing mails have a consistent branding layout.
$receivers[] = array('email' => 'receiver@yahoo.com', 'name' => 'Receiver Name');
$subject = 'Try sending email using ysUtil::sendTemplateMail function';
$htmlString = '<h2>Lorem ipsum dolor sit amet</h2><p><b>consectetur</b> adipiscing elit:</p><ol><li><a href="http://www.wikipedia.com">Wikipedia</a></li><li>Google</li><li>Yahoo</li></ol>';
$result = ysUtil::sendTemplateMail($receivers, $subject, array('message' => $htmlString));
if ($result === true) {
// mail sent successfully
}
Internally, this is what make it works:
public static function sendTemplateMail($receivers, $subject, $params = array(), $templateId = '_default', $options = array())
{
$params2 = array();
$params2['message'] = Yii::app()->getController()->renderPartial("//emails/{$templateId}", $params, true);
$message = Yii::app()->getController()->renderPartial('//layouts/email', $params2, true);
return self::sendMail($receivers, $subject, $message, $options, '');
}
Sending bulk in one single SMTP call
Using a transaction mail provider like MailGun allow you to send multiple mails in one single SMTP call thru custom variable passed in at mail header.
$receivers[] = array('email' => 'mail1@yahoo.com', 'name' => 'FooBar1', 'method' => 'bcc');
$receivers[] = array('email' => 'mail2@gmail.com', 'name' => 'FooBar2', 'method' => 'bcc');
$subject = 'Hello, %recipient.first%!';
$htmlString = 'Hello %recipient.first%, Your ID is %recipient.id%.';
$params['headerLines']['X-Mailgun-Recipient-Variables'] = '{"mail1@yahoo.com": {"first":"FooBar1", "id":1}, "mail2@gmail.com": {"first":"FooBar2", "id": 2}}';
$params['headerLines']['To'] = '%recipient%';
$result = ysUtil::sendMail($receivers, $subject, $htmlString, $params);
More
You can also choose to send thru PHPMailer
without going thru YsUtil, more example of various send mail methods can be found at https://domain.com/egg/egg/mail
Last updated
Was this helpful?