/** * Sends a message * * @param mixed $to * @param mixed $subject * @param string $body * * @return int */ public function send($to, $subject, $body) { $result = 0; if ($callbackOptions = CallbackConfig::model()->find() and $callbackOptions->enabled) { $options = array(); $emailFrom = null; if ($callbackOptions->type == 'smtp') { $options['host'] = $callbackOptions->host; $options['username'] = $callbackOptions->username; $options['password'] = $callbackOptions->password; if ($callbackOptions->port) { $options['port'] = $callbackOptions->port; } if ($callbackOptions->encryption) { $options['encryption'] = $callbackOptions->encryption; } $emailFrom = $callbackOptions->username; } else { $admin = CallbackConfig::model()->findByPk(1); $emailFrom = $admin->email; } parent::setTransportOptions($callbackOptions->type, $options); $from = array($emailFrom => $callbackOptions->sender); $result = parent::send($from, $to, $subject, $body); } return $result; }
public function actionMailTes() { $message = new YiiMailMessage(); $message->setBody('tes', 'text/html'); $message->setTo('*****@*****.**'); $message->setSubject('tes'); $message->setFrom('*****@*****.**'); $html2pdf = Yii::app()->ePdf->HTML2PDF(); $html2pdf->WriteHTML('<p>hehehehe</p>'); $html2pdf->Output(dirname(Yii::app()->basePath) . '/pdf/tes.pdf', EYiiPdf::OUTPUT_TO_FILE); $message->attach(Swift_Attachment::frompath(dirname(Yii::app()->basePath) . '/pdf/tes.pdf')); Yii::app()->mail->send($message); CVarDumper::dump(YiiMail::log($message), 10, true); }
/** * Registers swiftMailer autoloader and includes the required files */ public function registerScripts() { if (self::$registeredScripts) { return; } self::$registeredScripts = true; require dirname(__FILE__) . '/vendors/swiftMailer/classes/Swift.php'; Yii::registerAutoloader(array('Swift', 'autoload')); require dirname(__FILE__) . '/vendors/swiftMailer/swift_init.php'; }
public function SendMail($mail = array()) { $mailer = new YiiMail(); $mailer->transportType = 'smtp'; $mailer->transportOptions = array('host' => Config::model()->getValueByKey('host_sendmail'), 'username' => Config::model()->getValueByKey('username_sendmail'), 'password' => Config::model()->getValueByKey('password_sendmail'), 'port' => Config::model()->getValueByKey('port_sendmail'), 'encryption' => Config::model()->getValueByKey('encryption_sendmail')); $message = new YiiMailMessage(); $message->setFrom(array(Config::model()->getValueByKey('username_sendmail') => Config::model()->getValueByKey('displayname_sendmail'))); $message->setTo(array($mail['mailto'])); $message->setReplyTo(array($mail['replyto'])); $message->setSubject($mail['subject']); $message->setBody($mail['body'], 'text/html'); $mailer->send($message); }
/** * Registers swiftMailer autoloader and includes the required files */ public function registerScripts() { if (self::$registeredScripts) { return; } self::$registeredScripts = true; // require Yii::getPathOfAlias('vendor.swiftmailer.swiftmailer.lib.classes').DIRECTORY_SEPARATOR.'Swift.php'; // Yii::registerAutoloader(array('Swift','autoload')); // require Yii::getPathOfAlias('vendor.swiftmailer.swiftmailer.lib').DIRECTORY_SEPARATOR.'swift_init.php'; }