/** * testing method return array type */ public function testTypeFunction() { $model = new mailqueue(); $this->assertInternalType('object', $model->model()); $this->assertInternalType('array', $model->rules()); $this->assertInternalType('array', $model->attributeLabels()); $this->assertInternalType('object', $model->search()); }
public function run($args) { Yii::import('application.extensions.phpmailer.JPhpMailer'); if (Yii::app()->params['mailSystemActif'] == true) { $models = mailqueue::model()->findAll(); foreach ($models as $model) { $mail = new JPhpMailer(); $mail->IsSMTP(); $mail->Host = CommonProperties::$SMTP_SENDER_HOST; $mail->SMTPAuth = true; $mail->Port = CommonProperties::$SMTP_SENDER_PORT; $mail->Username = CommonProperties::$SMTP_SENDER_USERNAME; $mail->Password = CommonProperties::$SMTP_SENDER_PASSWORD; $mail->SetFrom(CommonProperties::$SMTP_SENDER_FROM_EMAIL, 'cbsd_platform'); $mail->Subject = $model->subject; $mail->AltBody = $model->body; $mail->MsgHTML($model->body); $mail->AddAddress($model->emailto, $model->emailto); $mail->CharSet = 'UTF-8'; if ($mail->Send()) { $model->delete(); } else { print_r($mail->ErrorInfo); } } } else { echo 'Le système d\'envoi de mail n\'est pas activé'; } }
/** * "send" an email. To do it, store an email into db and a crontask will pull emails to send them. * the crontask will be executed using the command line yiic sendmail. * @param unknown $to * @param unknown $subject * @param unknown $body */ public static function sendMail($to, $subject, $body) { $mailq = new mailqueue(); try { $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; $headers .= 'From: ' . CommonProperties::$SMTP_SENDER_FROM_EMAIL . "\r\n" . 'Reply-To: ' . CommonProperties::$SMTP_SENDER_FROM_EMAIL . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $mailq->emailto = $to; $subject = "{$subject}"; $mailq->subject = $subject; $mailq->body = $body; $mailq->headers = $headers; if (!$mailq->validate()) { Yii::log("pb sur validation mail", "error"); } return $mailq->save(); } catch (Exception $e) { Yii::log("exception sur save mail" . print_r($mailq->errors), "error"); } }
/** * "send" an email. To do it, store an email into db and a crontask will pull emails to send them. * the crontask will be executed using the command line yiic sendmail. * @param unknown $to * @param unknown $subject * @param unknown $body */ public static function sendMail($to, $subject, $body) { try { $mailq = new mailqueue(); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; $headers .= 'From: ' . CommonMailer::MAIL_FROM . "\r\n" . 'Reply-To: ' . CommonMailer::MAIL_FROM . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if (!CommonTools::isInDevMode()) { $mailq->emailto = $to; } else { $mailq->emailto = CommonMailer::MAIL_FROM; $subject = "Mail in dev_mod for {$to} : {$subject}"; } $mailq->subject = $subject; $mailq->body = $body; $mailq->headers = $headers; return $mailq->save(); } catch (Exception $e) { Yii::log("exception sur save mail", "error"); } }