/** * TODO * * @return string */ protected function contentInfoString($type = NULL, $file = NULL) { $data = $this->contentInfoArray($type, $file); foreach ($data as $key => $value) { $field[] = EmailHelper::fold(sprintf('%s: %s', $key, $value)); } return !empty($field) ? implode("\r\n", $field) . "\r\n\r\n" : NULL; }
/** * Creates the properly formatted InfoString based on the InfoArray. * * @see EmailGateway::contentInfoArray() * * @return string|null */ protected function contentInfoString($type = null, $file = null, $filename = null, $charset = null) { $data = $this->contentInfoArray($type, $file, $filename, $charset); $fields = array(); foreach ($data as $key => $value) { $fields[] = EmailHelper::fold(sprintf('%s: %s', $key, $value)); } return !empty($fields) ? implode("\r\n", $fields) . "\r\n\r\n" : null; }
/** * Send an email using an SMTP server * * @return bool */ public function send() { $this->validate(); $settings = array(); if ($this->_auth == true) { $settings['username'] = $this->_user; $settings['password'] = $this->_pass; } $settings['secure'] = $this->_secure; try { $this->_SMTP = new SMTP($this->_host, $this->_port, $settings); // Encode recipient names (but not any numeric array indexes) foreach ($this->_recipients as $name => $email) { $name = is_numeric($name) ? $name : EmailHelper::qEncode($name); $recipients[$name] = $email; } // Combine keys and values into a recipient list (name <email>, name <email>). $recipient_list = EmailHelper::arrayToList($recipients); // Encode the subject $this->_subject = EmailHelper::qEncode($this->_subject); // Encode the sender name if it's not empty $this->_sender_name = empty($this->_sender_name) ? NULL : EmailHelper::qEncode($this->_sender_name); // Build the 'From' header field body $from = empty($this->_sender_name) ? $this->_sender_email_address : $this->_sender_name . ' <' . $this->_sender_email_address . '>'; // Build the 'Reply-To' header field body if (!empty($this->_reply_to_email_address)) { if (!empty($this->_reply_to_name)) { $reply_to = EmailHelper::qEncode($this->_reply_to_name) . ' <' . $this->_reply_to_email_address . '>'; } else { $reply_to = $this->_reply_to_email_address; } } if (!empty($reply_to)) { $this->_header_fields = array_merge(array('Reply-To' => $reply_to), $this->_header_fields); } // Build the body text using attachments, html-text and plain-text. $this->prepareMessageBody(); // Build the header fields $this->_header_fields = array_merge(array('Message-ID' => sprintf('<%s@%s>', md5(uniqid()), HTTP_HOST), 'Date' => date('r'), 'From' => $from, 'Subject' => $this->_subject, 'To' => $recipient_list, 'X-Mailer' => 'Symphony Email Module', 'MIME-Version' => '1.0'), $this->_header_fields); // Set header fields and fold header field bodies foreach ($this->_header_fields as $name => $body) { $this->_SMTP->setHeader($name, EmailHelper::fold($body)); } // Send the email $this->_SMTP->sendMail($this->_sender_email_address, $this->_recipients, $this->_subject, $this->_body); } catch (SMTPException $e) { throw new EmailGatewayException($e->getMessage()); } return true; }
/** * Send an email using an SMTP server * * @throws EmailGatewayException * @throws EmailValidationException * @throws Exception * @return boolean */ public function send() { $this->validate(); $settings = array(); if ($this->_auth == true) { $settings['username'] = $this->_user; $settings['password'] = $this->_pass; } $settings['secure'] = $this->_secure; try { if (!is_a($this->_SMTP, 'SMTP')) { $this->_SMTP = new SMTP($this->_host, $this->_port, $settings); } // Encode recipient names (but not any numeric array indexes) $recipients = array(); foreach ($this->_recipients as $name => $email) { // Support Bcc header if (isset($this->_header_fields['Bcc']) && $this->_header_fields['Bcc'] == $email) { continue; } $name = empty($name) ? $name : EmailHelper::qEncode($name); $recipients[$name] = $email; } // Combine keys and values into a recipient list (name <email>, name <email>). $recipient_list = EmailHelper::arrayToList($recipients); // Encode the subject $subject = EmailHelper::qEncode((string) $this->_subject); // Build the 'From' header field body $from = empty($this->_sender_name) ? $this->_sender_email_address : EmailHelper::qEncode($this->_sender_name) . ' <' . $this->_sender_email_address . '>'; // Build the 'Reply-To' header field body if (!empty($this->_reply_to_email_address)) { $reply_to = empty($this->_reply_to_name) ? $this->_reply_to_email_address : EmailHelper::qEncode($this->_reply_to_name) . ' <' . $this->_reply_to_email_address . '>'; } if (!empty($reply_to)) { $this->_header_fields = array_merge($this->_header_fields, array('Reply-To' => $reply_to)); } // Build the body text using attachments, html-text and plain-text. $this->prepareMessageBody(); // Build the header fields $this->_header_fields = array_merge($this->_header_fields, array('Message-ID' => sprintf('<%s@%s>', md5(uniqid()), HTTP_HOST), 'Date' => date('r'), 'From' => $from, 'Subject' => $subject, 'To' => $recipient_list, 'X-Mailer' => 'Symphony Email Module', 'MIME-Version' => '1.0')); // Set header fields and fold header field bodies foreach ($this->_header_fields as $name => $body) { $this->_SMTP->setHeader($name, EmailHelper::fold($body)); } // Send the email command. If the envelope from variable is set, use that for the MAIL command. This improves bounce handling. $this->_SMTP->sendMail(is_null($this->_envelope_from) ? $this->_sender_email_address : $this->_envelope_from, $this->_recipients, $this->_body); if ($this->_keepalive == false) { $this->closeConnection(); } $this->reset(); } catch (SMTPException $e) { throw new EmailGatewayException($e->getMessage()); } return true; }