addCc() public méthode

Adds Cc-header and recipient, $email can be an array, or a single string address
public addCc ( string | array $email, string $name = '' ) : Zend_Mail
$email string | array
$name string
Résultat Zend_Mail Provides fluent interface
Exemple #1
0
 function __construct($template)
 {
     $this->_mailer = new Zend_Mail('koi8-r');
     $this->_view = new Zend_View();
     $this->_template = $template;
     $this->_view->setScriptPath(APPLICATION_PATH . '/views/scripts/email');
     $config = Bootstrap::get('config');
     $this->_mailer->addCc($config["mail"]["kadavr"]);
     $this->_mailer->addCc($config["mail"]["cc"]);
 }
Exemple #2
0
 public function send($template, array $values = array())
 {
     // create a new mail
     $mail = new Zend_Mail('UTF-8');
     if (isset($values['to'])) {
         if (is_array($values['to'])) {
             foreach ($values['to'] as $address) {
                 $mail->addTo($address);
             }
         } else {
             $mail->addTo($values['to']);
         }
         unset($values['to']);
     } else {
         throw new Exception('to not send in $values');
     }
     // set cc
     if (isset($values['cc'])) {
         if (is_array($values['cc'])) {
             foreach ($values['cc'] as $address) {
                 $mail->addCc($address);
             }
         } else {
             $mail->addCc($values['cc']);
         }
         unset($values['cc']);
     }
     // set bcc
     if (isset($values['bcc'])) {
         if (is_array($values['bcc'])) {
             foreach ($values['bcc'] as $address) {
                 $mail->addBcc($address);
             }
         } else {
             $mail->addBcc($values['bcc']);
         }
         unset($values['bcc']);
     }
     // get the template
     $templateModel = new Core_Model_Templates();
     $data = $templateModel->show($template, $values);
     // set subject and body
     $mail->setSubject($data['subject']);
     $mail->setBodyText($data['body']);
     if (empty(Daiquiri_Config::getInstance()->mail->debug)) {
         $mail->send();
     } else {
         Zend_Debug::dump($mail->getRecipients());
         Zend_Debug::dump($mail->getSubject());
         Zend_Debug::dump($mail->getBodyText());
     }
 }
Exemple #3
0
 /**
  * load the template and send the message
  *
  * @param string $recipient
  * @param array $from
  * @param string $subject
  * @param string $template
  * @param array $data
  * @param string $cc
  * @return bool
  */
 public function send($recipient, $from = array(), $subject, $message, $cc = false)
 {
     $config = Zend_Registry::get('config');
     $this->_view->addScriptPath($config->filepath->emailTemplates);
     $this->_view->emailBody = $message;
     $this->_mail->setBodyHtml($this->_view->render('template.phtml'));
     $this->_mail->setFrom($from[0], $from[1]);
     $this->_mail->addTo($recipient);
     if ($cc) {
         $this->_mail->addCc($cc);
     }
     $this->_mail->setSubject($subject);
     return $this->_mail->send($this->_transport);
 }
Exemple #4
0
 /**
  * Send an email.
  *
  * @param array $params Config object.
  *  Required keys: to, subject, message
  *  Optional keys: replyTo
  * @param array $viewParams Any values you wish to send to the HTML mail template
  * @param array $attachments
  * @return bool
  */
 public function send(array $params, array $viewParams = array(), $attachments = array())
 {
     $this->_validateParams($params);
     $mail = new Zend_Mail($this->getCharacterEncoding());
     $mail->setSubject($params['subject']);
     $mail->setBodyText($this->_getPlainBodyText($params));
     $mail->setFrom($this->getFromAddress(), $this->getFromName());
     $mail->addTo($params['to']);
     $viewParams['subject'] = $params['subject'];
     if ($this->getHtmlTemplate()) {
         $viewParams['message'] = isset($params['message']) ? $params['message'] : '';
         $viewParams['htmlMessage'] = isset($params['htmlMessage']) ? $params['htmlMessage'] : '';
         $mail->setBodyHtml($this->_renderView($viewParams));
     } elseif (isset($params['htmlMessage'])) {
         $mail->setBodyHtml($params['htmlMessage']);
     }
     if (!empty($params['replyTo'])) {
         $mail->setReplyTo($params['replyTo']);
     }
     if (!empty($params['cc'])) {
         $mail->addCc($params['cc']);
     }
     if (!empty($params['bcc'])) {
         $mail->addBcc($params['bcc']);
     }
     $this->addAttachments($attachments);
     $mimeParts = array_map(array($this, '_attachmentToMimePart'), $this->_attachments);
     array_walk($mimeParts, array($mail, 'addAttachment'));
     return $mail->send($this->getTransport());
 }
 public function contatoAction()
 {
     if ($this->_request->isPost()) {
         $html = new Zend_View();
         $html->setScriptPath(APPLICATION_PATH . '/modules/default/layouts/scripts/');
         $title = 'Contato | Instag';
         $to = '*****@*****.**';
         $cc = '*****@*****.**';
         $html->assign('title', $title);
         $html->assign('nome', $this->_request->getPost('nome'));
         $html->assign('email', $this->_request->getPost('email'));
         $html->assign('assunto', $this->_request->getPost('assunto'));
         $html->assign('mensagem', $this->_request->getPost('mensagem'));
         $mail = new Zend_Mail('utf-8');
         $bodyText = $html->render('contato.phtml');
         $config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => '*****@*****.**', 'password' => 'Inndeia123');
         $transport = new Zend_Mail_Transport_Smtp('127.0.0.1', $config);
         $mail->addTo($to);
         $mail->addCc($cc);
         $mail->setSubject($title);
         $mail->setFrom($this->_request->getPost('email'), $this->_request->getPost('name'));
         $mail->setBodyHtml($bodyText);
         $send = $mail->send($transport);
         if ($send) {
             $this->_helper->flashMessenger->addMessage('Sua mensagem foi enviada com sucesso, em breve entraremos em contato.');
         } else {
             $this->_helper->flashMessenger->addMessage('Falha no envio, tente novamente!');
         }
         $this->_redirect('/index');
     }
 }
 public static function sendMail($content)
 {
     $front = Zend_Controller_Front::getInstance();
     $email = new Base_Php_Overloader($front->getParam("bootstrap")->getOption('smtp'));
     $smtp = $email->domain;
     $username = $email->username;
     $password = $email->password;
     $port = $email->port;
     $config = new Zend_Mail_Transport_Smtp($smtp, array('auth' => 'login', 'username' => $username, 'password' => $password, 'ssl' => "ssl", 'port' => $port));
     Zend_Mail::setDefaultTransport($config);
     $mail = new Zend_Mail('UTF-8');
     $mail->setBodyHtml($content['body']);
     // Email body
     $mail->setFrom($content['sender'], $content['nameSender']);
     // Sender (Email, Name)
     $mail->addTo(isset($content['recipient']) ? $content['recipient'] : '', isset($content['nameRecipient']) ? $content['nameRecipient'] : '');
     // Recipient (Email, Name)
     $mail->addCc($content['sender'], $content['nameSender']);
     // CC to // Reply to Sender
     $mail->setSubject($content['subject']);
     // Subject Email
     try {
         $flag = $mail->send($config);
     } catch (Zend_Exception $e) {
         Base_Helper_Log::getInstance()->log(PHP_EOL . date('H:i:s :::: ') . ' [MAIL] ' . $e->getMessage());
         $flag = false;
     }
     if ($flag) {
         return true;
     } else {
         return false;
     }
 }
 protected function _sendEmail($history)
 {
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     $mail = new Zend_Mail('utf-8');
     $mail->addTo($history->getEmail());
     $mail->setBodyHTML($history->getBody());
     $mail->setSubject('=?utf-8?B?' . base64_encode($history->getSubject()) . '?=');
     $senderName = Mage::getStoreConfig(self::NAME_XML_PATH, $history->getStoreId());
     //Mage::getStoreConfig('trans_email/ident_general/name');
     $senderEmail = Mage::getStoreConfig(self::EMAIL_XML_PATH, $history->getStoreId());
     //Mage::getStoreConfig('trans_email/ident_general/email');
     $cc = Mage::getStoreConfig(self::CC_XML_PATH, $history->getStoreId());
     $mail->addCc($cc);
     $mail->setFrom($senderEmail, $senderName);
     try {
         if ((string) Mage::getConfig()->getNode('modules/Aschroder_SMTPPro/active') == 'true') {
             $transport = Mage::helper('smtppro')->getTransport();
             $mail->send($transport);
         } else {
             $mail->send();
         }
     } catch (Exception $e) {
         Mage::logException($e);
         return false;
     }
     return true;
 }
Exemple #8
0
 public function sendAction()
 {
     // 返回值数组
     $result = array();
     // 请求参数
     // $request = $this->getRequest()->getParams();
     $now = date('Y-m-d H:i:s');
     /* $data = array(
                'subject'       => $request['subject'],
                'to'            => $request['to'],
                'to_name'       => $request['to_name'],
                'cc'            => $request['cc'],
                'cc_name'       => $request['cc_name'],
                'content'       => $request['content'],
                'attachment'    => $request['attachment']
        ); */
     $data = array('subject' => 'test', 'to' => '*****@*****.**', 'to_name' => '新大陆', 'cc' => '*****@*****.**', 'cc_name' => 'leon', 'content' => 'test123测试', 'charset' => 'utf-8', 'attachment' => null);
     echo '<pre>';
     print_r($data);
     $mailConfig = new Zend_Config_Ini(CONFIGS_PATH . '/application.ini', 'mail');
     $from = $mailConfig->smtp->from;
     $fromname = $mailConfig->smtp->fromname;
     $transport = new Zend_Mail_Transport_Smtp($mailConfig->smtp->server, $mailConfig->smtp->params->toArray());
     $mail = new Zend_Mail();
     $mail->setSubject($data['subject']);
     $mail->setBodyText($data['content'], $data['charset']);
     $mail->setFrom($from, $fromname);
     $mail->addTo($data['to'], $data['to_name']);
     $mail->addCc($data['cc'], $data['cc_name']);
     $mail->addAttachment('MailController.php');
     $mail->createAttachment(file_get_contents('E:\\sina.png'), 'image/png', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, 'sina.png');
     print_r($mail->send($transport));
     //echo Zend_Json::encode($result);
     exit;
 }
Exemple #9
0
 /** Set up sending to addresses
  * @access protected
  * @param array $to
  * @param array $cc
  * @param array $from
  * @param array $bcc
  */
 protected function _setUpSending($to, $cc, $from, $bcc)
 {
     if (is_array($to)) {
         foreach ($to as $addTo) {
             $this->_mail->addTo($addTo['email'], $addTo['name']);
         }
     } else {
         $this->_mail->addTo('*****@*****.**', 'The PAS head office');
     }
     if (is_array($cc)) {
         foreach ($cc as $addCc) {
             $this->_mail->addCc($addCc['email'], $addCc['name']);
         }
     }
     if (is_array($from)) {
         foreach ($from as $addFrom) {
             $this->_mail->setFrom($addFrom['email'], $addFrom['name']);
         }
     } else {
         $this->_mail->setFrom('*****@*****.**', 'The PAS head office');
     }
     if (is_array($bcc)) {
         foreach ($bcc as $addBcc) {
             $this->_mail->addBcc($addBcc['email'], $addBcc['name']);
         }
     }
 }
Exemple #10
0
 /**
  * Add one or more "CC" email addresses.
  *
  * @param array|string $emails "CC" email address or addresses
  * @return $this this mail instance
  */
 public function addCc($emails)
 {
     parent::addCc($emails);
     if (!is_array($emails)) {
         $emails = array($emails);
     }
     foreach ($emails as $email) {
         $_cc[] = $email;
     }
     return $this;
 }
 public function addCc($email, $name = '')
 {
     if (Kwf_Registry::get('config')->debug->sendAllMailsTo) {
         if ($name) {
             $this->addHeader('X-Real-Cc', $name . " <" . $email . ">");
         } else {
             $this->addHeader('X-Real-Cc', $email);
         }
     } else {
         parent::addCc($email, $name);
     }
     return $this;
 }
Exemple #12
0
 /**
  * @param string $fromTitle
  * @param string $fromMail
  * @param string $toEmail
  * @param array $recipientCC
  * @param array $recipientBCC
  * @param string $subject
  * @param string $body
  * @param string $attachments
  * @param string $smtpHost
  * @param string $smtpPort
  * @param string $serverLogin
  * @param string $serverPassword
  * @param string $charCode
  * @param boolean $isHtml
  * @return type
  */
 public function handle($fromTitle, $fromMail, $toEmail, array $recipientCC, array $recipientBCC, $subject, $body, $attachments, $smtpHost = null, $smtpPort = null, $serverLogin = null, $serverPassword = null, $charCode = 'UTF-8', $isHtml = false, $replyto = null)
 {
     if ($smtpHost) {
         $params = array('name' => 'ZendMailHandler', 'port' => $smtpPort);
         if ($serverLogin) {
             $params['auth'] = 'login';
             $params['username'] = $serverLogin;
             $params['password'] = $serverPassword;
         }
         $transport = new Zend_Mail_Transport_Smtp($smtpHost, $params);
     } else {
         $transport = new Zend_Mail_Transport_Sendmail(array('name' => 'ZendMailHandler'));
     }
     $mail = new Zend_Mail($charCode);
     $mail->setFrom($fromMail, $fromTitle)->addTo($toEmail)->setSubject($subject);
     if (!empty($recipientCC)) {
         $mail->addCc($recipientCC);
     }
     if (!empty($recipientBCC)) {
         $mail->addBcc($recipientBCC);
     }
     //$mail->setReturnPath($replyto);
     if (!empty($replyto)) {
         $mail->setReplyTo($replyto);
     }
     if ($isHtml) {
         $mail->setBodyHtml($body);
     } else {
         $mail->setBodyText($body);
     }
     if (is_object($attachments) && $attachments->areAttachments()) {
         $mail->setType(Zend_Mime::MULTIPART_RELATED);
         $attachments->handle($mail);
     }
     if ($mail->send($transport)) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * @return void
  * @desc Re-build from data posted by this control the data object this control is editing
  */
 function BuildPostedDataObject()
 {
     $o_email = new Zend_Mail('UTF-8');
     if (isset($_POST['to']) and key_exists($_POST['to'], $this->a_addresses_md5)) {
         $o_email->addTo($this->a_addresses_md5[$_POST['to']]);
     }
     if (isset($_POST['from'])) {
         $o_email->setFrom($_POST['from'], (isset($_POST['fromName']) and $_POST['fromName']) ? $_POST['fromName'] : $_POST['from']);
     }
     if (isset($_POST['subject']) and $_POST['subject']) {
         $o_email->setSubject($_POST['subject']);
     } else {
         $o_email->setSubject($this->GetSettings()->GetSiteName() . ' contact form');
     }
     $body = isset($_POST['body']) ? $_POST['body'] : '';
     if (isset($_POST['reply'])) {
         $body .= "\n\n(The sender of this message has asked for a reply.)";
     }
     $o_email->setBodyText($body);
     if (isset($_POST['cc'])) {
         $o_email->addCc($_POST['from']);
     }
     $this->SetDataObject($o_email);
 }
Exemple #14
0
 /**
  * Method to send mail
  * @param array $options ($message, $to, $subject)
  */
 public function sendMail($options)
 {
     //$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => '*****@*****.**', 'password' => 'iruyeqij');
     //$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
     //Message Gears
     $config = array('ssl' => 'tls', 'port' => 2525, 'auth' => 'login', 'username' => '66917973', 'password' => '85cd337542324ca6addd1e821349dbf2');
     $smtpConnection = new Zend_Mail_Transport_Smtp('smtp.messagegears.net', $config);
     $html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><html><head></head><body style=\"background: #e2e2e2;\"><div style=\"width:600px !important; font-family:Arial; margin:auto; border:1px solid #e2e2e2; padding:15px; background: #fff; \" width=\"600\" ><table width='600' style='background: #fff; width:600px;'><tr><td valign='top'>" . $options['message'] . "</td></tr></table><br><br><br></div><br><br><br></body></html>";
     $html = wordwrap($html, 50);
     $html = preg_replace('/\\x00+/', '', $html);
     $mail = new Zend_Mail('utf-8');
     //$mail->setBodyText(strip_tags($options['message']));
     $mail->setBodyHTML($html);
     $mail->setFrom($this->_fromEmail, $this->_fromName);
     $mail->addTo($options['to']);
     if (isset($options['Bcc'])) {
         $mail->addBcc($options['Bcc']);
     }
     if (isset($options['cc'])) {
         $mail->addCc($options['cc']);
     }
     $mail->setSubject($options['subject']);
     $mail->send($smtpConnection);
 }
Exemple #15
0
 /**
  * Check if Header Fields are encoded correctly and if
  * header injection is prevented.
  */
 public function testHeaderEncoding()
 {
     $mail = new Zend_Mail();
     $mail->setBodyText('My Nice Test Text');
     // try header injection:
     $mail->addTo("testmail@example.com\nCc:foobar@example.com");
     $mail->addHeader('X-MyTest', "Test\nCc:foobar2@example.com", true);
     // try special Chars in Header Fields:
     $mail->setFrom('*****@*****.**', 'äüößÄÖÜ');
     $mail->addTo('*****@*****.**', 'äüößÄÖÜ');
     $mail->addCc('*****@*****.**', 'äüößÄÖÜ');
     $mail->setSubject('äüößÄÖÜ');
     $mail->addHeader('X-MyTest', 'Test-äüößÄÖÜ', true);
     $mock = new Zend_Mail_Transport_Mock();
     $mail->send($mock);
     $this->assertTrue($mock->called);
     $this->assertContains('From: =?iso8859-1?Q?"=E4=FC=F6=DF=C4=D6=DC"?=', $mock->header);
     $this->assertNotContains("\nCc:foobar@example.com", $mock->header);
     $this->assertContains('=?iso8859-1?Q?"=E4=FC=F6=DF=C4=D6=DC"=20?=<*****@*****.**>', $mock->header);
     $this->assertContains('Cc: =?iso8859-1?Q?"=E4=FC=F6=DF=C4=D6=DC"=20?=<*****@*****.**>', $mock->header);
     $this->assertContains('Subject: =?iso8859-1?Q?=E4=FC=F6=DF=C4=D6=DC?=', $mock->header);
     $this->assertContains('X-MyTest:', $mock->header);
     $this->assertNotContains("\nCc:foobar2@example.com", $mock->header);
     $this->assertContains('=?iso8859-1?Q?Test-=E4=FC=F6=DF=C4=D6=DC?=', $mock->header);
 }
 public function sendweeklyAction1()
 {
     $weeklyreport = new Application_Model_Report();
     $sendReportsTo = $weeklyreport->sendRportTo();
     $queueCount = count($sendReportsTo);
     $sendCount = 0;
     if (is_array($sendReportsTo)) {
         if (!empty($sendReportsTo)) {
             foreach ($sendReportsTo as $user) {
                 $mail = new Zend_Mail();
                 $mail->setBodyText('Please see the weekly report:');
                 $mail->setFrom('*****@*****.**', 'Textmunication.com');
                 $mail->addTo($user['email'], 'Joseph Saunders');
                 $mail->addCc('*****@*****.**', 'Wais Asefi');
                 //$mail->addCc('*****@*****.**', 'Robert Gonzalez');
                 $mail->setSubject('Weekly Reports');
                 // Get the Excel model
                 $excel = new Application_Model_Excel();
                 if ($weeklyreport->checkAdminUser($user['id']) and $user['id'] != 187) {
                     if (isset($user['edituser'])) {
                         $excelDataArray = $weeklyreport->getWeeklyReportByEditUser($user['edituser']);
                         //echo "single"; print_r($excelDataArray);   exit;
                         $date = date('Ymd');
                         $excelFileName = "weeklyreport_pollo" . $user['edituser'] . '_' . $date;
                         logWrite("Creating the Excel spreadsheets");
                         $excel = new Application_Model_Excel();
                         $excelFile = $excel->create($excelDataArray, $excelFileName);
                         logWrite("Attaching the spreadsheets");
                         $at = $mail->createAttachment(file_get_contents($excelFile['path']));
                         $at->filename = $excelFile['name'];
                     } else {
                         $excelDataArray = $weeklyreport->getWeeklyReport($user['id']);
                         $date = date('Ymd');
                         $excelFileName = "weeklyreport_clientid" . $user['id'] . '_' . $date;
                         $excel = new Application_Model_Excel();
                         $excelFile = $excel->create($excelDataArray, $excelFileName);
                         $at = $mail->createAttachment(file_get_contents($excelFile['path']));
                         $at->filename = $excelFile['name'];
                     }
                 } else {
                     // Get the subscriber datasets
                     $excelDataArray = $weeklyreport->getWeeklyReport();
                     //echo "<pre>"; print_r($excelDataArray);   exit;
                     // Get a date stamp for the file
                     $date = date('Ymd');
                     // Create our file names
                     $excelFileName = "weeklyreport_clientid" . $user['id'] . '_' . $date;
                     // Log the steps
                     //logWrite("Creating the Excel spreadsheets");
                     // Make the Excel files for each day
                     $excelFile = $excel->create($excelDataArray, $excelFileName);
                     $at = $mail->createAttachment(file_get_contents($excelFile['path']));
                     $at->filename = $excelFile['name'];
                 }
                 // Log the steps
                 //logWrite("Preparing to send...");
                 // Send it off
                 if (!$mail->send()) {
                     echo "MESSAGE NOT SENT";
                 } else {
                     echo "Message sent";
                 }
             }
         } else {
             $this->error = "No reports to send";
         }
     } else {
         $this->error = "Send to report was not properly fetched";
     }
 }
 public function sending(Zend_Form $form)
 {
     $request = Zend_Controller_Front::getInstance()->getRequest();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             //campos e valores
             $value = $form->getValues();
             //chaves de campos
             $key = array_keys($form->getValues());
             //chaves de campos file
             $key_file = array_keys($_FILES);
             //concatena chaves e valores do form
             if (!$this->message) {
                 $msg = "<table style='width:500px'>";
                 for ($i = 0; $i < count($key); $i++) {
                     $msg .= "<tr>";
                     $msg .= "<th style='padding:5px; background:#f1f1f1; font-weight:bold; border:1px solid #ccc; text-align:right'>";
                     $msg .= ucwords($key[$i]);
                     $msg .= "</th>";
                     $msg .= "<td style='padding:5px; border:1px solid #ccc'>";
                     $msg .= nl2br($value[$key[$i]]);
                     $msg .= "</td>";
                     $msg .= "</tr>";
                 }
                 $msg .= "</table>";
                 $this->message = $msg;
             }
             //envia email
             $mail = new Zend_Mail('utf-8');
             $mail->setFrom($this->from, $this->name);
             $mail->addTo($this->to);
             $mail->addBcc($this->bcc);
             $mail->addCc($this->cc);
             $mail->setBodyHtml($this->message);
             $mail->setSubject($this->assunto);
             for ($x = 0; $x < count($_FILES); $x++) {
                 //recebe nome de campos file
                 $file = $_FILES[$key_file[$x]];
                 //verifica se recebeu anexo
                 if ($file['error'] == 0) {
                     $filetmp = $file['tmp_name'];
                     $filename = $file['name'];
                     $filetype = $file['type'];
                     $filesize = $file['size'];
                     //anexo(s)
                     $mail->createAttachment(file_get_contents($filetmp), $filetype, Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $filename);
                 }
             }
             if (!empty($this->smtp) and !empty($this->username) and !empty($this->password)) {
                 //configuração smtp
                 $config = array('auth' => $this->auth, 'username' => $this->username, 'password' => $this->password, 'ssl' => $this->ssl, 'port' => $this->port);
                 //função smtp
                 $mailTransport = new Zend_Mail_Transport_Smtp($this->smtp, $config);
                 $mail->send($mailTransport);
             } else {
                 //envio normal
                 $mail->send();
             }
             //retorna para página informada
             header("location: " . $this->return);
         }
     }
 }
 /**
  * set mail recipients
  * 
  * @param Tinebase_Mail $_mail
  * @param Felamimail_Model_Message $_message
  * @return array
  */
 protected function _setMailRecipients(Zend_Mail $_mail, Felamimail_Model_Message $_message)
 {
     $nonPrivateRecipients = array();
     $punycodeConverter = $this->getPunycodeConverter();
     foreach (array('to', 'cc', 'bcc') as $type) {
         if (isset($_message->{$type})) {
             foreach ((array) $_message->{$type} as $address) {
                 $address = $punycodeConverter->encode($address);
                 if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                     Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Add ' . $type . ' address: ' . $address);
                 }
                 switch ($type) {
                     case 'to':
                         $_mail->addTo($address);
                         $nonPrivateRecipients[] = $address;
                         break;
                     case 'cc':
                         $_mail->addCc($address);
                         $nonPrivateRecipients[] = $address;
                         break;
                     case 'bcc':
                         $_mail->addBcc($address);
                         break;
                 }
             }
         }
     }
     return $nonPrivateRecipients;
 }
 /**
  * Send notifications
  *
  *
  */
 public function sendNotificationEmail($subject = "Notification", $body = "")
 {
     if (Mage::getStoreConfigFlag('system/smtp/disable')) {
         return $this;
     }
     if (!Mage::getStoreConfig(self::XML_PATH_GREATPLAINS_PRODUCT_UDATEDATA_CRON_NOTIFICATION_ACTIVE)) {
         //echo "Module is disabled!";
         return;
     }
     $to = (string) Mage::getStoreConfig(self::XML_PATH_GREATPLAINS_PRODUCT_UDATEDATA_CRON_RECIPIENT_EMAIL);
     if (empty($to)) {
         //echo "Can't send email. Please fill Notifications Recipient Email!";
         Mage::log("Can't send email. Please fill Notifications Recipient Email!", null, $this->logname, true);
         return;
     }
     $mail = new Zend_Mail();
     $mail->addTo($to);
     $cc = (string) Mage::getStoreConfig(self::XML_PATH_GREATPLAINS_PRODUCT_UDATEDATA_CRON_CC_EMAIL);
     if (!empty($cc)) {
         $mail->addCc($cc);
     }
     $mail->setBodyText($body);
     $mail->setSubject($subject);
     $mail->setFrom((string) Mage::getStoreConfig(self::XML_PATH_GREATPLAINS_PRODUCT_UDATEDATA_CRON_SENDER_EMAIL));
     try {
         $mail->send();
         Mage::log("Email was successfully send ", null, $this->logname, true);
     } catch (Exception $e) {
         Mage::log("Can't send email. Error: " . $e->getMessage(), null, $this->logname, true);
     }
 }
Exemple #20
0
$export = $soapClient->GetExportJobStatus(array('JobCode' => $manifest->JobCode));
if ($export->Status == "COMPLETE") {
    $csvfile = $export->FilePath;
    $handle = fopen($csvfile, "r");
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        if ($data[1] == "CLOSED") {
            $write->query("insert into `manifestdata` (manifest_code, manifest_status, manifest_date) values('" . $data[0] . "', '" . $data[1] . "', '" . $fromdate . "')");
        }
    }
} else {
    $export = $soapClient->GetExportJobStatus(array('JobCode' => $manifest->JobCode));
    $csvfile = $export->FilePath;
    $handle = fopen($csvfile, "r");
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        if ($data[1] == "CLOSED") {
            $write->query("insert into `manifestdata` (manifest_code, manifest_status, manifest_date) values('" . $data[0] . "', '" . $data[1] . "', '" . $fromdate . "')");
        }
    }
}
$body = "TEST Manifest.php";
$subject = $todate . " - Manifest.php";
$fromEmail = "*****@*****.**";
$toEmail = "*****@*****.**";
$mail = new Zend_Mail();
$mail->setBodyHtml($body);
$mail->setFrom($fromEmail);
$mail->addTo($toEmail);
$mail->addCc('*****@*****.**');
$mail->addCc('*****@*****.**');
$mail->setSubject($subject);
$mail->send();
Exemple #21
0
 public function __call($name, $arguments)
 {
     try {
         $this->_mail = new Zend_Mail('utf-8');
         $options = $arguments[0];
         $f = new Zend_Filter_Word_CamelCaseToDash();
         $tplDir = APPLICATION_PATH . '/entitys/mailing/templates/';
         $mailView = new Zend_View();
         $layoutView = new Zend_View();
         $mailView->setScriptPath($tplDir);
         $layoutView->setScriptPath($tplDir);
         $template = strtolower($f->filter($name)) . '.phtml';
         if (!is_readable(realpath($tplDir . $template))) {
             throw new Zend_Mail_Exception('No existe template para este email');
         }
         $mailConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/mail.ini', 'mail');
         $mailConfig = $mailConfig->toArray();
         $paramsTemplate = array();
         if (array_key_exists($name, $mailConfig)) {
             $paramsTemplate = $mailConfig[$name];
         } else {
             throw new Zend_Mail_Exception('No existe configuración para este template. Verificar mailing.ini');
         }
         $smtpHost = $mailConfig['mailServer'];
         //$smtpConf = $mailConfig['connectionData'][$paramsTemplate['sendAccount']];
         $smtpConf = $mailConfig['connectionData'];
         $transport = new Zend_Mail_Transport_Smtp($smtpHost, $smtpConf);
         if (!array_key_exists('subject', $paramsTemplate) || trim($paramsTemplate['subject']) == "") {
             throw new Zend_Mail_Exception('Subject no puede ser vacío, verificar mailing.ini');
         } else {
             $options['subject'] = $paramsTemplate['subject'];
             if (isset($paramsTemplate['from'])) {
                 $options['from'] = $paramsTemplate['from'];
                 $options['fromName'] = $paramsTemplate['fromName'];
             } else {
                 $options['from'] = $mailConfig['defaults']['from'];
                 $options['fromName'] = $mailConfig['defaults']['fromName'];
             }
         }
         if (!array_key_exists('to', $options)) {
             $options['to'] = $mailConfig['defaults']['from'];
             // throw new Zend_Mail_Exception('Falta indicar destinatario en $options["to"]');
         } else {
             $v = new Zend_Validate_EmailAddress();
             //            if (!$v->isValid($options['to'])) {
             //                //throw new Zend_Mail_Exception('Email inválido');
             //                // En lugar de lanzar un error, mejor lo logeo.
             //                $log = Zend_Registry::get('log');
             //                $log->warn('Email inválido: ' . $options['to']);
             //            }
         }
         foreach ($options as $key => $value) {
             $mailView->assign($key, $value);
             if (!is_array($value)) {
                 $options['subject'] = str_replace('{%' . $key . '%}', $value, $options['subject']);
                 $template = str_replace('{%' . $key . '%}', $value, $template);
             }
         }
         $mailView->mailData = $options;
         $layoutView->mailData = $options;
         //echo $template; exit;
         $mailView->addHelperPath('App/View/Helper', 'App_View_Helper');
         $layoutView->addHelperPath('App/View/Helper', 'App_View_Helper');
         $mailViewHtml = $mailView->render($template);
         //var_dump($transport);exit;
         //echo $mailViewHtml; exit;
         //$layoutView->assign('emailTemplate', $mailViewHtml);
         //$mailHtml = $layoutView->render('_layout.phtml');
         $this->_mail->setBodyHtml($mailViewHtml);
         $this->_mail->setFrom($options['from'], $options['fromName']);
         $this->_mail->addTo($options['to']);
         if (isset($paramsTemplate['Cc'])) {
             $Cc = explode(",", $paramsTemplate['Cc']);
             $this->_mail->addCc($Cc);
         }
         //            $this->_mail->setSubject($options['subject']);
         $this->_mail->setSubject($options['asunto']);
         $this->_mail->send($transport);
         $options['dataMailing']['from'] = $options['from'];
         $options['dataMailing']['subject'] = $options['subject'];
         $options['dataMailing']['template'] = $name;
         //            $modelMail = new Mailing_Model_Mailing();
         //            $modelMail->save($options['dataMailing']);
     } catch (Exception $ex) {
         $stream = @fopen(LOG_PATH . '/mailerror.log', 'a+', false);
         if (!$stream) {
             echo "Error al abrir log.";
         }
         $writer = new Zend_Log_Writer_Stream(LOG_PATH . '/mailerror.log');
         $logger = new Zend_Log($writer);
         $logger->info('***********************************');
         $logger->info('Template: ' . $name);
         $logger->info('Mail Data: ' . Zend_Json_Encoder::encode($arguments));
         $logger->info('Error Message: ' . $ex->getMessage());
         $logger->info('***********************************');
         $logger->info('');
     }
 }
         $model->InsertyInvoiceToOrders($res[DisplayOrderCode], $res[InvoiceCode], $res[CollectableAmount], $res[created_at], $duedate, $res[order_status], $s_id, $f_status);
         $model->savestatus($detail[email], $status, $updateat, $increment_id, $grand_total, $duedate);
     }
 }
 $tableInBody = $tableInBody . "</table>";
 $todate = Mage::getModel('core/date')->date('Y-m-d');
 $todate = $todate . "T00:00:00";
 $body = $tableInBody;
 $subject = $todate . " - New manifest Code Runing successfully for Delhi";
 $fromEmail = "*****@*****.**";
 $toEmail = "*****@*****.**";
 $mail = new Zend_Mail();
 $mail->setBodyHtml($body);
 $mail->setFrom($fromEmail);
 $mail->addTo($toEmail);
 $mail->addCc('*****@*****.**');
 $mail->addCc('*****@*****.**');
 $mail->setSubject($subject);
 $mail->send();
 echo "<br>fff";
 die;
 // Cancel orders
 /*$allcus=$model->getCreditCustomer();
 		foreach($allcus as $cus)
 		{
 			$getOrderQuery="select order_id from credit_user_orders where email='".$cus[email]."' and status != 'Completed' and status != 'Complete' and status != 'Canceled'";
 		    // //echo $cus[email]."<br>";
 		    $getOrder=$read->fetchAll($getOrderQuery);
 		    foreach($getOrder as $order)
 		    { 
 				$datas=Mage::getModel('sales/order')->loadByIncrementId($order[order_id]);
Exemple #23
0
    /**
     * 
     * @param type $options
     * @return string
     */
    public static function _checkMail($options = array())
    {
        $options['fromEmail'] = DONOTREPLYEMAIL;
        $options['fromName'] = SUPERADMIN_EMAIL;
        $orglogo = '';
        $imgsource = '';
        $Orgmodel = new Default_Model_Organisationinfo();
        $orglogoArr = $Orgmodel->getOrgLogo();
        if (!empty($orglogoArr)) {
            $orglogo = $orglogoArr['org_image'];
        }
        if ($orglogo != '') {
            $imgsource = DOMAIN . 'public/uploads/organisation/' . $orglogo;
        } else {
            $imgsource = MEDIA_PATH . 'images/mail_pngs/hrms_logo.png';
        }
        $header = "";
        $footer = "";
        $config = array('tls' => $options['tls'], 'auth' => $options['auth'], 'username' => $options['username'], 'password' => $options['password'], 'port' => $options['port']);
        $smtpServer = $options['server_name'];
        //end of sapplica mail configuration
        $transport = new Zend_Mail_Transport_Smtp($smtpServer, $config);
        Zend_Mail::setDefaultTransport($transport);
        $mail = new Zend_Mail('UTF-8');
        $htmlcontentdata = '
				<div style="width:100%;">
			            <div style="background-color:#eeeeee; width:80%; margin:0 auto; position:relative;">
			            <div><img src="' . $imgsource . '" onError="' . MEDIA_PATH . 'images/mail_pngs/hrms_logo.png" height="62" width="319" /></div>
			            <div style="padding:20px 20px 50px 20px;">
			                    <div>
			                        <h1 style="font-family:Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold; border-bottom:1px dashed #999; padding-bottom:15px;">' . $options['header'] . '</h1>
			                    </div>
			                    
			                    <div style="font-family:Arial, Helvetica, sans-serif; font-size:16px; font-weight:normal; line-height:30px; margin:0 0 20px 0;">
			                        ' . $options['message'] . '
			                    </div>
			                    
			                    <div style="font-family:Arial, Helvetica, sans-serif; font-size:16px; font-weight:normal; line-height:30px;">
			                        Regards,<br />
			                        <b>' . APPLICATION_NAME . '</b>
			                    </div>
			            </div>
			            </div>
			    </div>';
        $mail->setSubject($options['subject']);
        $mail->setFrom($options['fromEmail'], $options['fromName']);
        $mail->addTo($options['toEmail'], $options['toName']);
        $mail->setBodyHtml($htmlcontentdata);
        if (array_key_exists('bcc', $options)) {
            $mail->addBcc($options['bcc']);
        }
        if (array_key_exists('cc', $options)) {
            $mail->addCc($options['cc']);
        }
        try {
            if (!empty($options['toEmail'])) {
                $a = @$mail->send();
                return 'success';
            }
        } catch (Exception $ex) {
            $a = "error";
        }
        return $a;
    }
Exemple #24
0
 public function testReturnPath()
 {
     $mail = new Zend_Mail();
     $res = $mail->setBodyText('This is a test.');
     $mail->setFrom('*****@*****.**', 'test Mail User');
     $mail->setSubject('My Subject');
     $mail->addTo('*****@*****.**');
     $mail->addTo('*****@*****.**');
     $mail->addBcc('*****@*****.**');
     $mail->addBcc('*****@*****.**');
     $mail->addCc('*****@*****.**', 'Example no. 1 for cc');
     $mail->addCc('*****@*****.**', 'Example no. 2 for cc');
     // First example: from and return-path should be equal
     $mock = new Zend_Mail_Transport_Mock();
     $mail->send($mock);
     $this->assertTrue($mock->called);
     $this->assertEquals($mail->getFrom(), $mock->returnPath);
     // Second example: from and return-path should not be equal
     $mail->setReturnPath('*****@*****.**');
     $mock = new Zend_Mail_Transport_Mock();
     $mail->send($mock);
     $this->assertTrue($mock->called);
     $this->assertNotEquals($mail->getFrom(), $mock->returnPath);
     $this->assertEquals($mail->getReturnPath(), $mock->returnPath);
     $this->assertNotEquals($mock->returnPath, $mock->from);
 }
 private function _sendSettingsEmail($cc = false, $password = '', $isWelcome = false)
 {
     $mailer = new Zend_Mail();
     if ($isWelcome) {
         $mailer->setSubject(_("Welcome to your new mailbox on") . " {$this->_mailbox['domain']}");
     } else {
         $mailer->setSubject(_("Settings for your mailbox on") . " {$this->_mailbox['domain']}");
     }
     $mailer->setFrom($this->_options['server']['email']['address'], $this->_options['server']['email']['name']);
     $mailer->addTo($this->_mailbox['username'], $this->_mailbox['name']);
     if ($cc) {
         $mailer->addCc($cc);
     }
     $this->view->mailbox = $this->_mailbox;
     $this->view->welcome = $isWelcome;
     $this->view->password = $password;
     $settings = $this->_options['server'];
     foreach ($settings as $tech => $params) {
         foreach ($params as $k => $v) {
             $settings[$tech][$k] = Mailbox::substitute($this->_mailbox['username'], $v);
         }
     }
     $this->view->settings = $settings;
     $mailer->setBodyText($this->view->render('mailbox/email/settings.phtml'));
     try {
         $mailer->send();
         return true;
     } catch (Exception $e) {
     }
     return false;
 }
Exemple #26
0
 /**
  * Adds Cc-header and recipient, $email can be an array, or a single string address
  * Additionally adds recipients to temporary storage
  *
  * @param  string|array    $email
  * @param  string    $name
  * @return Pimcore_Mail Provides fluent interface
  */
 public function addCc($email, $name = '')
 {
     $this->addToTemporaryStorage('Cc', $email, $name);
     return parent::addCc($email, $name);
 }
 public function loginAction()
 {
     // Load model can thiet
     Zend_Loader::loadClass("UserModel");
     Zend_Loader::loadClass("GiftModel");
     Zend_Loader::loadClass("DailyGiftModel");
     Zend_Loader::loadClass("MessageModel");
     Zend_Loader::loadClass("AdvertiseModel");
     Zend_Loader::loadClass("RandomStringModel");
     //Lay va xu ly tham so
     $params = $this->_arrParam;
     if ($this->_request->isPost()) {
         if (!empty($params['user_name']) && !empty($params['password']) && !empty($params['game_id']) && isset($params['email']) && !empty($params['platform'])) {
             try {
                 $user_model = new UserModel();
                 // Tiền xử lý với những user bị block
                 $result = $user_model->checkAccount($params);
                 $message = "";
                 if ($result) {
                     if ($result['status'] == BLOCK_STATUS) {
                         if (time() > $result['active_time']) {
                             $user_model->update(array("status" => ACTIVE_STATUS), "user_id=" . $result['user_id']);
                         } else {
                             $message = "This account is temporarily blocked";
                         }
                     } else {
                         if ($result['status'] == DELETE_FOREVER_STATUS) {
                             $message = "This account has been permanently deleted";
                         }
                     }
                 }
                 if (empty($message)) {
                     $result = $user_model->checkLogin($params);
                     if ($result) {
                         // User dang nhap thanh cong
                         $a = Zend_Auth::getInstance();
                         $this->_user = $a->getIdentity();
                         $user = (object) $user_model->getUserInfo(array('user_id' => $this->_user->user_id, 'game_id' => $params['game_id']));
                         $where = "user_id = " . $user->user_id;
                         // Neu co email gui len thi xet
                         if (!empty($params['email'])) {
                             if (empty($user->email)) {
                                 $user_model->update(array("email" => $params['email']), $where);
                                 // Gui mail ve email nguoi dung de thong bao dang ki thanh cong neu co email gui len
                                 $html = "<div>Bạn đã đăng kí thành công tài khoản tại hệ thống game Zegome<br/>";
                                 $html .= "Tên tài khoản: " . $params['user_name'];
                                 $html .= "<br/><p align='center'><i>Liên hệ với chúng tôi: <b>Zegome team</b><br/>";
                                 $html .= ADDRESS_ZEGOME . "<br/>";
                                 $html .= "Email: " . EMAIL_ZEGOME . " - Tel: " . PHONE_ZEGOME . ".</i></p></div>";
                                 //      Gui mail
                                 $mail = new Zend_Mail('UTF-8');
                                 $mail->setBodyHtml($html);
                                 $mail->addTo($params['email']);
                                 $mail->addCc(EMAIL_ADMIN);
                                 $mail->setSubject('Đăng kí tài khoản tại hệ thống game Zegome');
                                 $mail->send();
                             }
                         }
                         $data = array();
                         $data['code'] = 1;
                         $content = array();
                         $content['user_gome'] = $user->user_gome;
                         $content["level"] = $user->level;
                         $content["total_win"] = $user->total_win;
                         $content["total_lose"] = $user->total_lose;
                         $content["achievement"] = $this->mapCapdo[$user->achievement_id]["name"];
                         $content["star"] = $user->star;
                         $content["max_star"] = $this->mapCapdo[$user->achievement_id]["max_star"];
                         $content["experiment"] = $user->experiment;
                         // Kiem tra hop qua tang xem co tin nhan ko?
                         $message_model = new MessageModel();
                         $list_message = $message_model->getList(array("user_id" => $user->user_id));
                         $message = array();
                         if (!empty($list_message) && count($list_message)) {
                             foreach ($list_message as $item) {
                                 $message[] = array("message_content" => $item['message'], "message_eng" => $item["message_eng"]);
                             }
                         }
                         $content['message'] = $message;
                         $advertise_model = new AdvertiseModel();
                         $list_advertise = $advertise_model->getList();
                         $advertise = array();
                         if (!empty($list_advertise) && count($list_advertise)) {
                             foreach ($list_advertise as $item) {
                                 $advertise[] = array("icon" => $item['icon'], "link" => $item["link"], "message_vn" => $item["message_vn"], "message_eng" => $item["message_eng"]);
                             }
                         }
                         $content['advertise'] = $advertise;
                         // Kiem tra hop qua tang xem co qua tang ko?
                         $gift_model = new GiftModel();
                         $list_gift = $gift_model->getList($params);
                         $gift = array();
                         if (!empty($list_gift) && count($list_gift)) {
                             foreach ($list_gift as $item) {
                                 $user_send_name = $item['user_send_name'] == "1" ? "Hệ thống Zegome" : $item['user_send_name'];
                                 $array = array("gift_id" => $item['id'], "user_send" => $user_send_name, "zegome_gold" => $item['zegome_gold'], "coupon" => $item['coupon'], "message" => $item['message']);
                                 $gift[] = $array;
                             }
                         }
                         $content['gift'] = $gift;
                         $data['content'] = $content;
                         // Kiem tra xem co qua tang hang ngay ko?
                         $daily_gift = array();
                         if ($user->daily_gift < date("Y-m-d")) {
                             $daily_gift_model = new DailyGiftModel();
                             $list_gift = $daily_gift_model->getDailyGift($params);
                             if (!empty($list_gift) && count($list_gift)) {
                                 foreach ($list_gift as $item) {
                                     $user_model->update(array("user_gome" => new Zend_Db_Expr("user_gome + " . $item['zegome_gold']), "daily_gift" => date("Y-m-d")), "user_id = " . $user->user_id);
                                     $this->__updateSession();
                                     $array = array("zegome_gold" => $item['zegome_gold'], "message" => $item['message']);
                                     $daily_gift[] = $array;
                                 }
                             }
                         }
                         if (!empty($daily_gift)) {
                             $content['daily_gift'] = $daily_gift;
                         } else {
                             $content['daily_gift'] = "Không có quà tặng";
                         }
                         $data['content'] = $content;
                     } else {
                         $data = array("code" => 0, "content" => "Authentication failed");
                     }
                 } else {
                     $data = array("code" => 0, "content" => $message);
                 }
             } catch (exception $e) {
                 $data = array("code" => 0, "content" => "Error in server");
             }
         } else {
             $data = array("code" => 0, "content" => "Invalid parameters");
         }
         echo json_encode($data);
     }
     exit;
 }
    $tables = "<table>";
    $tables .= "<tr><td>Product SKU</td><td>Product Name</td></tr>";
    foreach ($items_dis_ins as $items_dis_in) {
        $prod = Mage::getModel('catalog/product')->load($items_dis_in['product_id']);
        //$products[] = $items_dis_in['product_id'];
        if ($prod->getStatus() == 1) {
            //echo $prod->getSku();
            //$query_pro = "UPDATE catalog_product_entity_int SET value='2' WHERE entity_id ='".$items_dis_in['product_id']."' and attribute_id = '96'";
            $query_pro = "UPDATE catalog_product_entity_int SET value='1' WHERE entity_id ='" . $items_dis_in['product_id'] . "' and attribute_id = '102'";
            $writeConnection->query($query_pro);
            //$prod->setStatus(2);
            //$prod->save();
            $tables .= "<tr><td>" . $prod->getSku() . "</td><td>" . $prod->getName() . "</td></tr>";
        }
    }
    $tables .= "</tr></table>";
    //echo $tables; exit;
    $todate = date('Y-m-d');
    $body = "<h5>Not Visibility Products</h5>" . $tables;
    $subject = $todate . " - Not Visibility Products for based on 90 days and out of stock";
    $fromEmail = "*****@*****.**";
    $toEmail = "*****@*****.**";
    $mail = new Zend_Mail();
    $mail->setBodyHtml($body);
    $mail->setFrom($fromEmail);
    $mail->addTo($toEmail);
    $mail->addCc('*****@*****.**');
    $mail->addCc('*****@*****.**');
    $mail->setSubject($subject);
    $mail->send();
}
Exemple #29
0
 public function send()
 {
     if (is_null($this->_from)) {
         throw new Exception('You need to set the from address');
     }
     // send the mail
     $mail = new Zend_Mail();
     $mail->setSubject($this->_title);
     if ($this->_isHtml) {
         $mail->setBodyHtml($this->_message);
     } else {
         $mail->setBodyText($this->_message);
     }
     $mail->setFrom($this->_from);
     $toCount = count($this->_to);
     if (!empty($this->_to)) {
         for ($i = 0; $i < $toCount; $i++) {
             $mail->addTo($this->_to[$i]);
         }
     }
     $ccCount = count($this->_cc);
     if (!empty($this->_cc)) {
         for ($i = 0; $i < $ccCount; $i++) {
             $mail->addCc($this->_cc[$i]);
         }
     }
     $bccCount = count($this->_bcc);
     if (!empty($this->_bcc)) {
         for ($i = 0; $i < $bccCount; $i++) {
             $mail->addBcc($this->_bcc[$i]);
         }
     }
     $mail->send();
 }
Exemple #30
0
/**
 * Sends mail using server settings specified in app.conf/global.conf
 *
 * Parameters are:
 *
 * 	$pa_to: 	Email address(es) of message recipients. Can be a string containing a single email address or
 *				an associative array with keys set to multiple addresses and corresponding values optionally set to
 *				a human-readable recipient name.
 *	$pa_from:	The email address of the message sender. Can be a string containing a single email address or
 *				an associative array with keys set to multiple addresses and corresponding values optionally set to
 *				a human-readable sender name.
 *	$ps_subject:	The subject line of the message
 *	$ps_body_text:	The text of the message				(optional)
 *	$ps_html_text:	The HTML-format text of the message (optional)
 * 	$pa_cc: 	Email address(es) of cc'ed message recipients. Can be a string containing a single email address or
 *				an associative array with keys set to multiple addresses and corresponding values optionally set to
 *				a human-readable recipient name. (optional)
 * 	$pa_bcc: 	Email address(es) of bcc'ed message recipients. Can be a string containing a single email address or
 *				an associative array with keys set to multiple addresses and corresponding values optionally set to
 *				a human-readable recipient name. (optional)
 * 	$pa_attachment: 	array containing file path, name and mimetype of file to attach.
 *				keys are "path", "name", "mimetype"
 *
 * While both $ps_body_text and $ps_html_text are optional, at least one should be set and both can be set for a 
 * combination text and HTML email
 */
function caSendmail($pa_to, $pa_from, $ps_subject, $ps_body_text, $ps_body_html = '', $pa_cc = null, $pa_bcc = null, $pa_attachment = null)
{
    $o_config = Configuration::load();
    $o_log = new Eventlog();
    $va_smtp_config = array();
    if ($o_config->get('smtp_auth')) {
        $vs_smtp_auth = $o_config->get('smtp_auth');
    } else {
        $vs_smtp_auth = '';
    }
    if ($o_config->get('smtp_username')) {
        $vs_smtp_uname = $o_config->get('smtp_username');
        $vs_smtp_auth = 'login';
    } else {
        $vs_smtp_uname = '';
    }
    if ($o_config->get('smtp_password')) {
        $vs_smtp_pw = $o_config->get('smtp_password');
        $vs_smtp_auth = 'login';
    } else {
        $vs_smtp_pw = '';
    }
    $va_smtp_config = array('username' => $vs_smtp_uname, 'password' => $vs_smtp_pw);
    if ($vs_smtp_auth) {
        $va_smtp_config['auth'] = $vs_smtp_auth;
    }
    if ($vs_ssl = $o_config->get('smtp_ssl')) {
        $va_smtp_config['ssl'] = $vs_ssl;
    }
    if ($vs_port = $o_config->get('smtp_port')) {
        $va_smtp_config['port'] = $vs_port;
    }
    try {
        if ($o_config->get('smtp_use_sendmail_transport')) {
            $vo_tr = new Zend_Mail_Transport_Sendmail($o_config->get('smtp_server'), $va_smtp_config);
        } else {
            $vo_tr = new Zend_Mail_Transport_Smtp($o_config->get('smtp_server'), $va_smtp_config);
        }
        $o_mail = new Zend_Mail('UTF-8');
        if (is_array($pa_from)) {
            foreach ($pa_from as $vs_from_email => $vs_from_name) {
                $o_mail->setFrom($vs_from_email, $vs_from_name);
            }
        } else {
            $o_mail->setFrom($pa_from);
        }
        if (!is_array($pa_to)) {
            $pa_to = array($pa_to => $pa_to);
        }
        foreach ($pa_to as $vs_to_email => $vs_to_name) {
            if (is_numeric($vs_to_email)) {
                $o_mail->addTo($vs_to_name, $vs_to_name);
            } else {
                $o_mail->addTo($vs_to_email, $vs_to_name);
            }
        }
        if (is_array($pa_cc) && sizeof($pa_cc)) {
            foreach ($pa_cc as $vs_to_email => $vs_to_name) {
                if (is_numeric($vs_to_email)) {
                    $o_mail->addCc($vs_to_name, $vs_to_name);
                } else {
                    $o_mail->addCc($vs_to_email, $vs_to_name);
                }
            }
        }
        if (is_array($pa_bcc) && sizeof($pa_bcc)) {
            foreach ($pa_bcc as $vs_to_email => $vs_to_name) {
                if (is_numeric($vs_to_email)) {
                    $o_mail->addBcc($vs_to_name, $vs_to_name);
                } else {
                    $o_mail->addBcc($vs_to_email, $vs_to_name);
                }
            }
        }
        if (is_array($pa_attachment) && $pa_attachment["path"]) {
            $ps_attachment_url = $pa_attachment["path"];
            # --- only attach media if it is less than 50MB
            if (filesize($ps_attachment_url) < 419430400) {
                $vs_file_contents = file_get_contents($ps_attachment_url);
                $o_attachment = $o_mail->createAttachment($vs_file_contents);
                if ($pa_attachment["name"]) {
                    $o_attachment->filename = $pa_attachment["name"];
                }
                if ($pa_attachment["mimetype"]) {
                    $o_attachment->type = $pa_attachment["mimetype"];
                }
            }
        }
        $o_mail->setSubject($ps_subject);
        if ($ps_body_text) {
            $o_mail->setBodyText($ps_body_text);
        }
        if ($ps_body_html) {
            $o_mail->setBodyHtml($ps_body_html);
        }
        $o_mail->send($vo_tr);
        $o_log->log(array('CODE' => 'SYS', 'SOURCE' => 'Registration', 'MESSAGE' => _t('Registration confirmation email was sent to %1', join(';', array_keys($pa_to)))));
        return true;
    } catch (Exception $e) {
        $o_log->log(array('CODE' => 'ERR', 'SOURCE' => 'Registration', 'MESSAGE' => _t('Could not send registration confirmation email to %1: %2', join(';', array_keys($pa_to)), $e->getMessage())));
        return false;
    }
}