Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MailController extends \Phalcon\Mvc\Controller
- {
- /**
- * Отправка письма.
- * @param $to
- * @param string $subject
- * @param string $message
- * @param string $from
- */
- public function sendMail($to, $subject = '', $message = '', $from = '', $attach = array()) {
- if (!$to) {
- return 'Mailer Error: Не указан получатель';
- }
- global $config;
- $mail = new PHPMailer;
- $mail->isSMTP();
- //$mail->SMTPDebug = true;
- //$mail->Debugoutput = 'html';
- if ($attach != array()) {
- foreach ($attach as $att) {
- $mail->addAttachment($att);
- }
- }
- $mail->CharSet = 'UTF-8';
- $mail->Host = $config['mail']['smtp']['server'];
- $mail->Port = $config['mail']['smtp']['port'];
- $mail->SMTPSecure = $config['mail']['smtp']['security'];
- $mail->SMTPAuth = true;
- $mail->Username = $config['mail']['smtp']['username'];
- $mail->Password = $config['mail']['smtp']['password'];
- if ($from == '') {
- $mail->setFrom($config['mail']['fromEmail'], $config['mail']['fromName']);
- } else {
- $mail->setFrom($from);
- }
- $mail->addAddress($to);
- $mail->Subject = $subject;
- $mail->msgHTML($message);
- if (!$mail->send()) {
- return 'Mailer Error: ' . $mail->ErrorInfo;
- } else {
- return 'ok';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement