/** * Test case for a simple email text message with * multiple recipients. * */ public function testOnlyText() { $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'); $mock = new Zend_Mail_Transport_Mock(); $mail->send($mock); $this->assertTrue($mock->called); $this->assertEquals('My Subject', $mock->subject); $this->assertEquals('*****@*****.**', $mock->from); $this->assertContains('*****@*****.**', $mock->recipients); $this->assertContains('*****@*****.**', $mock->recipients); $this->assertContains('*****@*****.**', $mock->recipients); $this->assertContains('*****@*****.**', $mock->recipients); $this->assertContains('*****@*****.**', $mock->recipients); $this->assertContains('*****@*****.**', $mock->recipients); $this->assertContains('This is a test.', $mock->body); $this->assertContains('Content-Transfer-Encoding: quoted-printable', $mock->header); $this->assertContains('Content-Type: text/plain', $mock->header); $this->assertContains('From: "test Mail User" <*****@*****.**>', $mock->header); $this->assertContains('Subject: My Subject', $mock->header); $this->assertContains('To: <*****@*****.**>', $mock->header); $this->assertContains('Cc: "Example no. 1 for cc" <*****@*****.**>', $mock->header); }
public function askAction() { $form = Model_Static_Loader::loadForm('forum'); $forumModel = new Model_DbTable_Forum(); if ($this->getRequest()->isPost() && $form->isValid($_POST)) { $question = $forumModel->createRow($form->getValues()); if (preg_match('/^\\w+[\\w-\\.]*\\@\\w+((-\\w+)|(\\w*))\\.[a-z]{2,3}$/', $question->email) && ($question->category == 'Вопросы и запросы' || $question->category == 'Отзывы и предложения' || $question->category == 'Книга жалоб')) { $question->content = str_replace("\n", "<br/>\n", $question->content); $question->save(); $users = new Zend_Config_Xml(APPLICATION_PATH . "/config/admins.xml"); $users = $users->toArray(); $mailer = new Zend_Mail("UTF-8"); $mailer->setFrom($question->email, $question->author); $mailer->setSubject("форум"); // wdaemon 2013-02-08 $mailer->setBodyHtml ( "Новый вопрос: " . $question->content, "utf8", "UTF-8"); $mailer->setBodyHtml("Новый вопрос: " . $question->content); $mailer->addTo("*****@*****.**", "ALPHA-HYDRO info"); $mailer->addBcc("*****@*****.**", "Fedonov Roman A."); $mailer->addBcc("*****@*****.**", "Быков Дмитрий Владимирович"); foreach ($users as $user) { if ($user["role"] == "administrator") { $mailer->addTo($user['email'], $user['name']); } } $mailer->send(); $this->view->error = 0; } else { $this->view->error = 1; } } else { $this->_redirect($this->view->url(array("action" => "index"))); return; } }
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()); } }
private function GetEmailAddresses($s_sql, Zend_Mail $email) { $a_send = null; if ($s_sql) { $result = $this->GetDataConnection()->query($s_sql); while ($o_row = $result->fetch()) { # first up, if this is a review item, get the title if (isset($o_row->title)) { $this->s_review_item_title = $o_row->title; } # check if person in the previous subscriptions if (!is_array($this->a_emails) or !in_array($o_row->email, $this->a_emails)) { #...add to email list $a_send[] = $o_row->email; # ... add also to list of people sent, to exclude from further emails $this->a_emails[] = $o_row->email; } } $result->closeCursor(); if (is_array($a_send)) { foreach ($a_send as $address) { $email->addBcc($address); } } } return is_array($a_send); }
/** 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']); } } }
/** * 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()); }
/** * Send all messages in a queue * * @return Mage_Core_Model_Email_Queue */ public function send() { /** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */ $collection = Mage::getModel('core/email_queue')->getCollection()->addOnlyForSendingFilter()->setPageSize(self::MESSAGES_LIMIT_PER_CRON_RUN)->setCurPage(1)->load(); ini_set('SMTP', Mage::getStoreConfig('system/smtp/host')); ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port')); /** @var $message Mage_Core_Model_Email_Queue */ foreach ($collection as $message) { if ($message->getId()) { $parameters = new Varien_Object($message->getMessageParameters()); if ($parameters->getReturnPathEmail() !== null) { $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail()); Zend_Mail::setDefaultTransport($mailTransport); } $mailer = new Zend_Mail('utf-8'); foreach ($message->getRecipients() as $recipient) { list($email, $name, $type) = $recipient; switch ($type) { case self::EMAIL_TYPE_BCC: $mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?='); break; case self::EMAIL_TYPE_TO: case self::EMAIL_TYPE_CC: default: $mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?='); break; } } if ($parameters->getIsPlain()) { $mailer->setBodyText($message->getMessageBody()); } else { $mailer->setBodyHTML($message->getMessageBody()); } $mailer->setSubject('=?utf-8?B?' . base64_encode($parameters->getSubject()) . '?='); $mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName()); if ($parameters->getReplyTo() !== null) { $mailer->setReplyTo($parameters->getReplyTo()); } if ($parameters->getReturnTo() !== null) { $mailer->setReturnPath($parameters->getReturnTo()); } try { //$mailer->send(); $mailer->send(Mage::helper('smtp')->getTransport()); unset($mailer); $message->setProcessedAt(Varien_Date::formatDate(true)); $message->save(); } catch (Exception $e) { unset($mailer); $oldDevMode = Mage::getIsDeveloperMode(); Mage::setIsDeveloperMode(true); Mage::logException($e); Mage::setIsDeveloperMode($oldDevMode); return false; } } } return $this; }
private function SEND_SMTP_ZEND() { try { loadLibrary("ZEND", "Zend_Mail"); loadLibrary("ZEND", "Zend_Mail_Transport_Smtp"); if (empty($this->MailText)) { $this->MailText = ">>"; } if ($this->Account->Authentication == "No") { $config = array('port' => $this->Account->Port); } else { $config = array('auth' => 'login', 'username' => $this->Account->Username, 'password' => $this->Account->Password, 'port' => $this->Account->Port); } if (!empty($this->Account->SSL)) { $config['ssl'] = $this->Account->SSL == 1 ? 'SSL' : 'TLS'; } $transport = new Zend_Mail_Transport_Smtp($this->Account->Host, $config); $mail = new Zend_Mail('UTF-8'); $mail->setBodyText($this->MailText); $mail->setFrom($this->Account->Email, $this->Account->SenderName); if (strpos($this->Receiver, ",") !== false) { $emails = explode(",", $this->Receiver); $add = false; foreach ($emails as $mailrec) { if (!empty($mailrec)) { if (!$add) { $add = true; $mail->addTo($mailrec, $mailrec); } else { $mail->addBcc($mailrec, $mailrec); } } } } else { $mail->addTo($this->Receiver, $this->Receiver); } $mail->setSubject($this->Subject); $mail->setReplyTo($this->ReplyTo, $name = null); if ($this->Attachments != null) { foreach ($this->Attachments as $resId) { $res = getResource($resId); $at = $mail->createAttachment(file_get_contents("./uploads/" . $res["value"])); $at->type = 'application/octet-stream'; $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $at->encoding = Zend_Mime::ENCODING_BASE64; $at->filename = $res["title"]; } } $mail->send($transport); } catch (Exception $e) { if ($this->TestIt) { throw $e; } else { handleError("111", $this->Account->Host . " send mail connection error: " . $e->getMessage(), "functions.global.inc.php", 0); } return 0; } return 1; }
/** * Add one or more "BCC" email addresses. * * @param array|string $emails "BCC" email address or addresses * @return $this this mail instance */ public function addBcc($emails) { parent::addBcc($emails); if (!is_array($emails)) { $emails = array($emails); } foreach ($emails as $email) { $_bcc[] = $email; } return $this; }
public function addBcc($email) { if (!is_array($email)) { $email = array($email); } foreach ($email as $recipient) { $this->bcc[] = $recipient; parent::addBcc($email); } return $this; }
/** * Função para envio de notificações via e-mail * @param string $title * @param array $destination * @param string $bodyMessage */ protected function sendMail($title, $destination, $bodyMessage) { try { $mail = new Zend_Mail('UTF-8'); $mail->setSubject($title); $mail->addBcc($destination); $mail->setBodyHtml($bodyMessage); $mail->send(); } catch (Exception $e) { /* TODO Colocar Loogues aqui */ } }
/** * send email using smtp.gmail.com * @param array $options for sending mail * @return boolean */ public static function send($options) { $body = ''; $config = Zend_Registry::get('smtpConfig'); if (isset($options['from']['email']) && $options['from']['email'] != '') { $fromAddress = $options['from']['email']; } else { $fromAddress = $config->fromAddress; } if ($config->isSendMails == true) { if (!empty($options['template']) && file_exists(APPLICATION_PATH . $options['template'])) { $template = new App_File(APPLICATION_PATH . $options['template']); $body = $template->contents; if (is_array($options['additional'])) { foreach ($options['additional'] as $key => $value) { $body = str_replace('{' . $key . '}', $value, $body); } } if (is_array($options['data'])) { foreach ($options['data'] as $key => $value) { $body = str_replace('{' . $key . '}', $value, $body); } } } else { $body = $options['body']; } $smtpConfig = array('ssl' => $config->ssl, 'port' => $config->port, 'auth' => $config->auth, 'username' => $config->username, 'password' => $config->password); $transport = new Zend_Mail_Transport_Smtp($config->host, $smtpConfig); $mail = new Zend_Mail('utf-8'); $mail->setBodyHtml($body); $mail->setFrom($config->fromAddress, $config->fromName); $mail->setReplyTo($fromAddress, $config->fromName); //if (APPLICATION_ENV == 'production') { foreach ($options['to'] as $to) { $to['label'] = empty($to['label']) ? $to['email'] : $to['label']; $mail->addTo($to['email'], $to['label']); } //} else { //$mail->addTo($config->toAddress, $config->toName); //} if (isset($options['bcc']['email']) && !empty($options['bcc']['email'])) { $mail->addBcc($options['bcc']['email']); } $mail->setSubject($options['subject']); try { $mail->send($transport); return true; } catch (Zend_Exception $e) { return $e->getMessage(); } } return false; }
/** * Sends contact email */ private function sendMail($subject, $message, $fromName, $fromEmail) { $mail = new Zend_Mail('UTF-8'); $mail->addTo('*****@*****.**'); $mail->addBcc('*****@*****.**'); $mail->setSubject($subject); $mail->setBodyText($message . PHP_EOL . 'Sender IP: ' . $_SERVER['REMOTE_ADDR']); $mail->setFrom('*****@*****.**', 'Unsee.cc'); $mail->setReplyTo($fromEmail, $fromName); $mail->setDefaultTransport(new Zend_Mail_Transport_Sendmail()); try { return $mail->send(); } catch (Exception $e) { } }
public function send(Model_Comment $comment, Model_Post $post) { $mail = new Zend_Mail(); $mail->setSubject('Comment posted on robkeplin.com'); $message = $comment->name . ', <br><br> You\'ve successfully posted a cmment on www.robkeplin.com! You can view it <a href="http://www.robkeplin.com/blog/view/' . urlencode($post->category->name) . '/' . urlencode($post->title) . '/">here</a>.<br><br> Thanks, <br />Rob<br /><a href="http://www.robkeplin.com">www.robkeplin.com</a>'; $mail->setBodyHtml($message); $mail->setFrom('*****@*****.**', 'Rob Keplin'); $mail->addTo($comment->email); $mail->addBcc('*****@*****.**'); $this->_send($mail); }
private function sendEmail($emailMessage, $recipients) { $mailerConfig = Zend_Registry::get("config")->mail; $transport = new Zend_Mail_Transport_Smtp($mailerConfig->host, $mailerConfig->smtpconfig->toArray()); Zend_Mail::setDefaultTransport($transport); $email = new Zend_Mail('UTF-8'); $email->setHeaderEncoding(Zend_Mime::ENCODING_BASE64); $email->addHeader('Content-type', 'text/html'); $email->setFrom($emailMessage->getSenderAddress(), $emailMessage->getSenderName()); $email->setSubject($emailMessage->getSubject()); $email->setBodyHtml($emailMessage->getBody(), 'UTF-8'); foreach ($recipients as $recipient) { $email->addBcc($recipient->getAddress(), $recipient->getName()); } $email->send(); }
/** * @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; } }
public static function sendMail($docid, $params) { // $cfg = Zend_Registry::get('cfg'); // $tr = new Zend_Mail_Transport_Smtp($cfg['post']['smtp']); // Zend_Mail::setDefaultTransport($tr); $mail = new Zend_Mail('UTF-8'); // $mail->setFrom('*****@*****.**', 'CSMU site'); $recipients = self::getRecipients($docid); $toNames = array_keys($recipients); $toEmails = array_values($recipients); $toEmails = explode(',', $toEmails[$params['to']]); $mail->addTo(array_shift($toEmails), $toNames[$params['to']]); if ($params['replyto']) { $mail->setFrom($params['replyto']); } // else $mail->setFrom('*****@*****.**', 'Не отвечать!'); // else $mail->clearReplyTo(); $mail->addBcc($toEmails); $mail->setSubject($toNames[$params['to']]); $mail->setBodyText($params['body']); $mail->send(); }
public function sendmailAction() { $this->_helper->layout->disablelayout(true); $this->_helper->viewRender->setNoRender(true); $sys = new Default_Model_System(); $list = $sys->list_system(); $content = $list[0]['content_email']; $date = date("d-m-Y"); $mail = new Zend_Mail('utf-8'); $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->setBodyHtml($content, 'utf-8'); $mail->setFrom("*****@*****.**", "Khách hàng rong biển"); // $mail->addBcc("*****@*****.**", 'Support Southern Breeze '); // $mail->addBcc("*****@*****.**", 'Sales Southern Breeze '); $mail->addTo("*****@*****.**", "Form contact rong biển"); $mail->addBcc("*****@*****.**", 'Ly Le'); //$mail->addBcc("*****@*****.**", 'Truong Van Hung'); $mail->setSubject("Khách hàng rong biển ({$date})"); $mail->send(); exit; }
/** * 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); }
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); }
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(); }
/** * * @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; }
/** * Adds Bcc recipient, $email can be an array, or a single string address * Additionally adds recipients to temporary storage * * @param string|array $email * @return Pimcore_Mail Provides fluent interface */ public function addBcc($email) { $this->addToTemporaryStorage('Bcc', $email, ''); return parent::addBcc($email); }
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); } } }
/** * send mail helper * @author tri.van * @param $email * @param $subject * @param $message * @param $mailUserName * @param $mailFrom * @since Tue Now 3, 9:48 AM */ private function sendMail($email, $subject, $message, $mailUserName, $mailFrom) { try { //Prepare email $mail = new Zend_Mail('UTF-8'); //add headers avoid the mail direction to 'spam'/ 'junk' folder $mail->addHeader('MIME-Version', '1.0'); $mail->addHeader('Content-Type', 'text/html'); $mail->addHeader('Content-Transfer-Encoding', '8bit'); $mail->addHeader('X-Mailer:', 'PHP/' . phpversion()); $mail->setFrom($mailUserName, $mailFrom); //add reply to avoid the mail direction to 'spam'/ 'junk' folder $mail->setReplyTo($mailFrom, $subject); $mail->addTo($email); $mail->addBcc($mailUserName); $mail->setSubject($subject); $mail->setBodyHtml($message); //Send it! $mail->send(); return array(true, ""); } catch (Exception $e) { $sent = $e->getMessage(); return array(false, $sent); } }
/** * Populate mail instance * * @param Zend_Mail $mail * @return Zend_Mail */ public function populate(Zend_Mail $mail) { if ($this->fromEmail || $this->fromName) { $mail->setFrom($this->fromEmail, $this->fromName); } if ($this->toEmail || $this->toName) { $mail->addTo($this->toEmail, $this->toName); } if ($this->bcc) { if (!is_array($this->bcc)) { $mail->addBcc($this->bcc); } else { if (isset($this->bcc['email']) && !empty($this->bcc['email'])) { if (isset($this->bcc['name']) && !empty($this->bcc['name'])) { $mail->addBcc($this->bcc['email'], $this->bcc['name']); } else { $mail->addBcc($this->bcc['email']); } } elseif (count($this->bcc)) { foreach ($this->bcc as $bcEmail) { $mail->addBcc($bcEmail); } } } } if ($this->subject) { $mail->setSubject($this->subject); } if ($this->bodyHtml) { $mail->setBodyHtml($this->bodyHtml); } if ($this->bodyText) { $mail->setBodyText($this->bodyText); } if ($this->attachments && is_array($this->attachments)) { foreach ($this->attachments as $file) { if (file_exists($file['path'])) { $fileContent = file_get_contents($file['path']); if ($fileContent) { $attachment = new Zend_Mime_Part($fileContent); $attachment->type = Zend_Mime::TYPE_OCTETSTREAM; $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $attachment->encoding = Zend_Mime::ENCODING_BASE64; $attachment->filename = basename($file['path']); $attachment->id = md5(time()); $attachment->description = $attachment->filename; $mail->addAttachment($attachment); } } } } if ($this->sendExternal) { $mail->addHeader('SEND_TO_EXTERNAL_SMTP', 'True'); } return $mail; }
/** * 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; }
/** * Функция настроена для отправки сообщений через mail.russ-call.ru * ИСПРАВЛЯТЬ ОСТОРОЖНО! Может не доставляться почта или сообщения * пойдут в спам * * @param Forum_Model_Forum $post * @return $this */ public function sendAdminMail(Forum_Model_Forum $post) { $mailToAdmin = new Zend_Mail("utf-8"); //$mailToAdmin->setFrom($post->getEmail(), $post->getAuthor()); $mailToAdmin->setFrom("*****@*****.**", "Alpha-Hydro"); $mailToAdmin->setSubject("Alpha-Hydro.Forum."); $mailToAdmin->setReturnPath("*****@*****.**"); $textHtml = '<p>Автор: ' . $post->getAuthor() . ' (' . $post->getEmail() . ')</p>'; $textHtml .= '<p>Категория: ' . $post->getCategory() . '</p>'; $textHtml .= '<p><b>Сообщение:</b></p>'; $textHtml .= $post->getContent(); $mailToAdmin->setBodyHtml($textHtml); //$mailToAdmin->addTo("*****@*****.**", "Alpha-Hydro"); $mailToAdmin->addTo("*****@*****.**", "Alpha-Hydro"); $mailToAdmin->addBcc(array("*****@*****.**", "*****@*****.**", "*****@*****.**")); //$mailToAdmin->addBcc('*****@*****.**'); $mailToAdmin->send(); return $this; }
function send() { global $config; //echo "export show data"; // Create authentication with SMTP server $authentication = array(); if($config->email->smtp_auth == true) { $authentication = array( 'auth' => 'login', 'username' => $config->email->username, 'password' => $config->email->password, 'ssl' => $config->email->secure, 'port' => $config->email->smtpport ); } $transport = new Zend_Mail_Transport_Smtp($config->email->host, $authentication); // Create e-mail message $mail = new Zend_Mail('utf-8'); $mail->setType(Zend_Mime::MULTIPART_MIXED); $mail->setBodyText($this->notes); $mail->setBodyHTML($this->notes); $mail->setFrom($this->from, $this->from_friendly); $to_addresses = preg_split('/\s*[,;]\s*/', $this->to); if (!empty($to_addresses)) { foreach ($to_addresses as $to) { $mail->addTo($to); } } if (!empty($this->bcc)) { $bcc_addresses = preg_split('/\s*[,;]\s*/', $this->bcc); foreach ($bcc_addresses as $bcc) { $mail->addBcc($bcc); } } $mail->setSubject($this->subject); if($this->attachment) { // Create attachment #$spc2us_pref = str_replace(" ", "_", $preference[pref_inv_wording]); $content = file_get_contents('./tmp/cache/'.$this->attachment); $at = $mail->createAttachment($content); $at->type = 'application/pdf'; $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $at->filename = $this->attachment; } // Send e-mail through SMTP try { $mail->send($transport); } catch(Zend_Mail_Protocol_Exception $e) { echo '<strong>Zend Mail Protocol Exception:</strong> ' . $e->getMessage(); exit; } // Remove temp invoice unlink("./tmp/cache/$this->attachment"); switch ($this->format) { case "invoice": { // Create succes message $message = "<meta http-equiv=\"refresh\" content=\"2;URL=index.php?module=invoices&view=manage\">"; $message .= "<br />$this->attachment has been emailed"; break; } case "statement": { // Create succes message $message = "<meta http-equiv=\"refresh\" content=\"2;URL=index.php?module=statement&view=index\">"; $message .= "<br />$this->attachment has been emailed"; break; } case "cron": { // Create succes message $message .= "<br />Cron email for today has been sent"; break; } case "cron_invoice": { // Create succes message $message .= "$this->attachment has been emailed"; break; } } return $message; }
public function remittance_email($batch_id, $shop_date_remittance) { //generate remittance Invoice $this->remittanceInvoice($batch_id, $shop_date_remittance); // send the remittance_email $mailto = APPLICATION_ENV != 'production' ? '*****@*****.**' : $this->email; $mail = new Zend_Mail(); $mail->setFrom('*****@*****.**', 'Momento Shop'); $mail->addTo($mailto); $mail->setSubject('Momento Shop Remittance ' . date('d-m-Y')); $mail->setBodyHtml($this->emailRemittanceBody($batch_id, $shop_date_remittance)); $hasGstremittance = $this->hasGstremittance($batch_id, $shop_date_remittance); if ($hasGstremittance) { //attachement $fileContents = file_get_contents(APPLICATION_PATH . '/../tmp/remittance_invoice/' . $this->id . '-' . $batch_id . '.pdf'); $file = $mail->createAttachment($fileContents); $file->filename = $this->id . '-' . $batch_id . '.pdf'; } $mail->addBcc('*****@*****.**'); $sent = $mail->send(); }