示例#1
0
 public function sendAction()
 {
     include 'Mail.php';
     $data = $_POST;
     $headers['From'] = $data['username'];
     $headers['Subject'] = $data['subject'];
     $headers['Date'] = date("r");
     $recipients = array();
     if (is_array($data['to'])) {
         foreach ($data['to'] as $to) {
             $recipients[] = $to;
         }
     } else {
         $recipients[] = $data['to'];
     }
     if (array_key_exists('body', $data)) {
         $body = $data['body'];
     } else {
         $body = "";
     }
     $params['host'] = EmailConfiguration::getSmtpHost();
     $params['port'] = EmailConfiguration::getSmtpPort();
     $params['auth'] = EmailConfiguration::getSmtpAuth();
     $params['username'] = $data['username'];
     $params['password'] = $data['password'];
     // Create the mail object using the Mail::factory method
     $mail_object =& Mail::factory('smtp', $params);
     $mail_object->send($recipients, $headers, $body);
 }
示例#2
0
 /**
  * Init htmlMimeMail5, EmailConfiguration, EmailNotificationConfiguration.
  * Set smtp params, sendmailpath, from.
  **/
 public function __construct()
 {
     $this->emailNotificationConfig = new EmailNotificationConfiguration();
     $confObj = new EmailConfiguration();
     $this->mailType = $confObj->getMailType();
     if ($this->mailType == 'smtp') {
         $config = array();
         $authType = $confObj->getSmtpAuth();
         if ($authType != EmailConfiguration::EMAILCONFIGURATION_SMTP_AUTH_NONE) {
             $config['auth'] = strtolower($authType);
             $config['username'] = trim($confObj->getSmtpUser());
             $config['password'] = trim($confObj->getSmtpPass());
         }
         $security = $confObj->getSmtpSecurity();
         if ($security != EmailConfiguration::EMAILCONFIGURATION_SMTP_SECURITY_NONE) {
             $config['ssl'] = strtolower($security);
         }
         $config['port'] = trim($confObj->getSmtpPort());
         $transport = new Zend_Mail_Transport_Smtp($confObj->getSmtpHost(), $config);
     } else {
         if ($this->mailType = 'sendmail') {
             $transport = new Zend_Mail_Transport_Sendmail();
         }
     }
     Zend_Mail::setDefaultTransport($transport);
     $this->mailer = new Zend_Mail();
     $this->mailer->setFrom($confObj->getMailAddress(), "OrangeHRM");
 }
示例#3
0
function sendMultipartMail($subject, $to, $txtbody = '', $htmlbody = '', $username, $password, $replyto = false, $attachment = null, $cc = false, $ext = null)
{
    error_log("[sendMultipartMail] Subject: {$subject}, To: " . var_export($to, true) . "CC: " . var_export($cc, true));
    if (ApplicationConfiguration::isProductionInstance() === FALSE) {
        return;
    }
    $message = new Mail_mime();
    $message->setTXTBody($txtbody);
    $message->setHTMLBody($htmlbody);
    if ($attachment !== null) {
        if (isset($attachment['data'])) {
            if (isset($attachment['type'])) {
                $type = $attachment['type'];
            } else {
                $type = 'application/octem-stream';
            }
            if (isset($attachment['name'])) {
                $name = $attachment['name'];
            } else {
                $name = 'attachment.dat';
            }
            $message->addAttachment($attachment['data'], $type, $name, false);
        }
    }
    $body = $message->get();
    $recipients = array();
    $extheaders = array('From' => $username, 'Subject' => $subject, 'Date' => date("r"));
    if (is_array($ext) && isset($ext["From"])) {
        $extheaders["From"] = $ext["From"];
    }
    if (is_array($ext) && isset($ext["Precedence"])) {
        $extheaders["Precedence"] = $ext["Precedence"];
    }
    if ($replyto !== false && trim($replyto) != '') {
        $extheaders["Reply-To"] = $replyto;
        $extheaders["Bcc"] = $replyto;
        $recipients[] = $replyto;
        $headers["Bcc"] = $replyto;
    }
    if ($cc !== false && $cc !== null && is_numeric($cc) == false) {
        if (is_array($cc) && count($cc) > 0) {
            $extCc = implode(",", $cc);
            $extheaders["Cc"] = $extCc;
            $recipients = array_merge($recipients, $cc);
        } else {
            if (trim($cc) !== "") {
                $extheaders["Cc"] = $cc;
                $recipients[] = $cc;
            }
        }
    }
    $headers = $message->headers($extheaders);
    if (is_array($to)) {
        foreach ($to as $_to) {
            $recipients[] = $_to;
        }
    } else {
        $recipients[] = $to;
    }
    $params['host'] = EmailConfiguration::getSmtpHost();
    $params['port'] = EmailConfiguration::getSmtpPort();
    $params['auth'] = EmailConfiguration::getSmtpAuth();
    $params['username'] = $username;
    $params['password'] = $password;
    // Create the mail object using the Mail::factory method
    $mail_object = Mail::factory('smtp', $params);
    // Split mail sending operations in bunches of 10 recipients at a time
    $rec = array();
    $recipients2 = array_unique($recipients);
    $recipients = array();
    foreach ($recipients2 as $recipient) {
        $recipients[] = $recipient;
    }
    error_log("sendMultipartMail recipients: " . var_export($recipients, true));
    for ($i = 0; $i < count($recipients); $i++) {
        $rec[] = $recipients[$i];
        if ($i % 10 === 0 && $i > 0) {
            $mail_object->send($rec, $headers, $body);
            $rec = array();
        }
    }
    if (count($rec) > 0) {
        $mail_object->send($rec, $headers, $body);
    }
}
示例#4
0
 /**
  * List Mail Configuration
  * @param sfWebRequest $request
  * @return unknown_type
  */
 public function executeListMailConfiguration(sfWebRequest $request)
 {
     $emailConfiguration = new EmailConfiguration();
     $this->mailAddress = $emailConfiguration->getSentAs();
     $this->sendMailPath = $emailConfiguration->getSendMailPath();
     $this->smtpAuth = $emailConfiguration->getSmtpAuthType();
     $this->smtpSecurity = $emailConfiguration->getSmtpSecurityType();
     $this->smtpHost = $emailConfiguration->getSmtpHost();
     $this->smtpPort = $emailConfiguration->getSmtpPort();
     $this->smtpUser = $emailConfiguration->getSmtpUsername();
     $this->smtpPass = $emailConfiguration->getSmtpPassword();
     $this->emailType = $emailConfiguration->getMailType();
     if ($this->getUser()->hasFlash('templateMessage')) {
         $this->templateMessage = $this->getUser()->getFlash('templateMessage');
     }
 }
 private function __setDefaultValues(EmailConfiguration $emailConfiguration)
 {
     $this->setDefaults(array('txtMailAddress' => $emailConfiguration->getSentAs(), 'cmbMailSendingMethod' => $emailConfiguration->getMailType(), 'txtSendmailPath' => $emailConfiguration->getSendmailPath(), 'txtSmtpHost' => $emailConfiguration->getSmtpHost(), 'txtSmtpPort' => $emailConfiguration->getSmtpPort(), 'optAuth' => $emailConfiguration->getSmtpAuthType(), 'txtSmtpUser' => $emailConfiguration->getSmtpUsername(), 'txtSmtpPass' => $emailConfiguration->getSmtpPassword(), 'optSecurity' => $emailConfiguration->getSmtpSecurityType(), 'txtTestEmail' => ''));
 }