本文整理汇总了PHP中Zend_Mail::addAttachment方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Mail::addAttachment方法的具体用法?PHP Zend_Mail::addAttachment怎么用?PHP Zend_Mail::addAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Mail
的用法示例。
在下文中一共展示了Zend_Mail::addAttachment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Envia e-mail para usuário com dados iniciais, como username (e-mail) e senha.
* @param int $idpessoa
* @param int $idEncrontro
* @param int $tipoMensagem use as constantes definidas acima [ MSG_CONFIRMACAO, MSG_RECUPERAR_SENHA ].
* @param binary $pdf arquivo PDF em string binária, se não for null será enviado ao usuário em anexo
* @throws Exception
*/
public function send($id_pessoa, $id_encontro, $tipoMensagem = Application_Model_EmailConfirmacao::MSG_CONFIRMACAO, $pdf = null)
{
$mail = new Zend_Mail();
$pessoa = new Application_Model_Pessoa();
$linha = $pessoa->find($id_pessoa)->current();
$emailText = $this->obterMensagem($id_encontro, $tipoMensagem);
switch ($tipoMensagem) {
case Application_Model_EmailConfirmacao::MSG_CONFIRMACAO:
case Application_Model_EmailConfirmacao::MSG_RECUPERAR_SENHA:
$result = $pessoa->gerarToken($id_pessoa);
$link = "http://" . $_SERVER["SERVER_NAME"] . "/index/definir-senha/hashedToken/" . $result['hashedToken'] . "/id/" . $id_pessoa;
break;
case Application_Model_EmailConfirmacao::MSG_CONFIRMACAO_REINSCRICAO:
$link = "";
break;
default:
throw new Exception(_("Send e-mail option not defined."));
}
$emailText->mensagem = str_replace('{nome}', $linha->nome, $emailText->mensagem);
$emailText->mensagem = str_replace('{email}', $linha->email, $emailText->mensagem);
$emailText->mensagem = str_replace('{href_link}', $link, $emailText->mensagem);
$mail->setBodyHtml(iconv($this->config->email->in_charset, $this->config->email->out_charset, $emailText->mensagem));
$mail->addTo($linha->email, $linha->nome);
$mail->setSubject(iconv($this->config->email->in_charset, $this->config->email->out_charset, $emailText->assunto));
if ($pdf != null) {
$at = new Zend_Mime_Part($pdf);
$at->type = 'application/pdf';
$at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = 'ticket-inscricao.pdf';
$mail->addAttachment($at);
}
$mail->send();
}
示例2: sendAction
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' => '14706931@qq.com', 'to_name' => '新大陆', 'cc' => 'leonli188@126.com', '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;
}
示例3: sendFile
private function sendFile($filePath, $emailAddress, $headerMessage)
{
$file = $filePath;
$mail = new Zend_Mail();
$mail->setFrom(Yii::app()->params['adminEmail']);
$mail->addTo($emailAddress);
$mail->setSubject($headerMessage);
$mail->setBodyHtml($headerMessage);
$at = new Zend_Mime_Part(file_get_contents($file));
$at->type = $this->mime_type($file);
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = basename($file);
$mail->addAttachment($at);
return $mail->send();
}
示例4: _sendMail
/**
* Fonction d'envoi d'email
* @param array $params
* @return send mail
*/
protected function _sendMail($params)
{
$params['message'] .= '<p><i>Email envoyé depuis le fichier ' . $params['file'] . ' le ' . date('Y-m-d-H:i:s') . '</p>';
//Destinataire du mail
if ($params['recipient']) {
$recipient = $params['recipient'];
} else {
$recipient = Mage::getStoreConfig('system/hhennes_alerts/alert_email_default_recipient');
}
//Gestion des destinataires multiples :
if (preg_match('#;#', $recipient)) {
$recipents = explode(';', $recipient);
}
//Gestion de l'expéditeur et de son nom
if (Mage::getStoreConfig('system/hhennes_alerts/alert_email_sender') && Mage::getStoreConfig('system/hhennes_alerts/alert_email_sender') != '') {
$senderEmail = Mage::getStoreConfig('system/hhennes_alerts/alert_email_sender');
} else {
$senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');
}
if (Mage::getStoreConfig('system/hhennes_alerts/alert_email_sender_name') && Mage::getStoreConfig('system/hhennes_alerts/alert_email_sender_name') != '') {
$senderName = Mage::getStoreConfig('system/hhennes_alerts/alert_email_sender_name');
} else {
$senderName = Mage::getStoreConfig('trans_email/ident_general/name');
}
$mail = new Zend_Mail('UTF-8');
$mail->setFrom($senderEmail, $senderName);
//Si destinataires multiples
if ($recipents) {
foreach ($recipents as $emailCopy) {
$mail->addTo($emailCopy);
}
} else {
$mail->addTo($recipient);
}
$mail->setSubject($params['subject'])->setBodyHtml($params['message']);
//Si il y'a une pièce jointe
if ($params['attachment']) {
$attachement = new Zend_Mime_Part(file_get_contents($params['attachment']));
$attachement->type = 'text/csv';
$attachement->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachement->encoding = Zend_Mime::ENCODING_BASE64;
$attachement->filename = $params['attachment_name'];
$mail->addAttachment($attachement);
}
//Envoi de l'email
$mail->send();
}
示例5: SendExcelByMail
public function SendExcelByMail($status, $liqId)
{
$param = array();
if ($status) {
$param = array('compress' => 0, 'Attachment' => 0);
}
$html = $this->displayLiqTable($liqId, $filename, $provEmail, $provName);
$mail = new Zend_Mail('utf-8');
$at = new Zend_Mime_Part($html);
$at->type = 'application/vnd.ms-excel';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = $filename . '.xls';
$mail->addTo($provEmail);
$mail->addAttachment($at);
$mail->setSubject('Notificación de Operación');
$mail->setBodyHtml("<p>Estimados {$provName}:<br /><br />Buen día, este es un envío automático de la próxima operación que realizaremos. Para ver el archivo adjunto por favor descargalo (opcion DESCARGAR) en tu computadora y luego abrilo, si al abrir aparece algún aviso de error o de cambio de Formato, simplemente dale 'SI' para afirmar que lo queres abrir, es que el envio llega en un formato WEB.<br /><br />\nEspero la confirmación de que lo hayas recibido para combinar detalles de día y horario. <br /><br />\nSaludo Cordialmente,<br /><br />\nGustavo Yurgel</p>");
$mail->send();
return 'success';
}
示例6: sendMail
private function sendMail($toEmail, $fromEmail, $fromName, $subject, $body, array $attachments = array())
{
$mail = new Zend_Mail('UTF-8');
$mail->addTo($toEmail)->setFrom($fromEmail, $fromName)->setSubject($subject)->setBodyText($body, null, Zend_Mime::ENCODING_8BIT);
foreach ($attachments as $attachment) {
$mail->addAttachment($attachment);
}
$mail->send();
}
示例7: testAttachment
/**
* check if attachment handling works
*
*/
public function testAttachment()
{
$mail = new Zend_Mail();
$mail->setBodyText('My Nice Test Text');
$mail->addTo('testmail@example.com', 'Test Recipient');
$mail->setFrom('mymail@example.com', 'Test Sender');
$mail->setSubject('Test: Attachment Test with Zend_Mail');
$at = $mail->addAttachment('abcdefghijklmnopqrstuvexyz');
$at->type = 'image/gif';
$at->id = 12;
$at->filename = 'test.gif';
$mock = new Zend_Mail_Transport_Mock();
$mail->send($mock);
// now check what was generated by Zend_Mail.
// first the mail headers:
$this->assertContains('Content-Type: multipart/mixed', $mock->header);
$boundary = $mail->getMimeBoundary();
$this->assertContains('boundary="' . $boundary . '"', $mock->header);
$this->assertContains('MIME-Version: 1.0', $mock->header);
// check body
// search for first boundary
$p1 = strpos($mock->body, "--{$boundary}\n");
$this->assertNotEquals(null, $p1);
// cut out first (Text) part
$start1 = $p1 + 3 + strlen($boundary);
$p2 = strpos($mock->body, "--{$boundary}\n", $start1);
$this->assertNotEquals(null, $p2);
$partBody1 = substr($mock->body, $start1, $p2 - $start1);
$this->assertContains('Content-Type: text/plain', $partBody1);
$this->assertContains('My Nice Test Text', $partBody1);
// check second (HTML) part
// search for end boundary
$start2 = $p2 + 3 + strlen($boundary);
$p3 = strpos($mock->body, "--{$boundary}--");
$this->assertNotEquals(null, $p3);
$partBody2 = substr($mock->body, $start2, $p3 - $start2);
$this->assertContains('Content-Type: image/gif', $partBody2);
$this->assertContains('Content-Transfer-Encoding: base64', $partBody2);
$this->assertContains('Content-ID: <12>', $partBody2);
}
示例8: populate
/**
* 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;
}
示例9: sendMail
function sendMail($mailTo, $mailSubject, $mailMessage, $mailFrom, $mailBcc)
{
global $scriptVersion, $returnPath;
//var_dump($mailFrom);
if (preg_match('/(.+)(\\s<.+\\@.+>)$/', $mailFrom, $tmp)) {
$mailFrom_1 = $tmp[1];
$mailFrom_2 = $tmp[2];
$tmp[1] = mb_encode_mimeheader($tmp[1]);
$mailFrom = $tmp[1] . $tmp[2];
}
//var_dump($mailFrom);
$mailHeader = "From: {$mailFrom}\n";
if ($mailBcc) {
$mailHeader .= "Bcc: {$mailBcc}\n";
}
/*
$php_ver = phpversion();
$mailHeader .= "X-Mailer: Sapphirus.Biz Formmail/{$scriptVersion}(PHP/{$php_ver})";
$mailMessage = preg_replace('/\r\n|\r/', "\n", $mailMessage);
if (isset($returnPath) && $returnPath) {
mb_send_mail($mailTo, $mailSubject, $mailMessage, $mailHeader, "-f{$returnPath}");
} else {
mb_send_mail($mailTo, $mailSubject, $mailMessage, $mailHeader);
}
return true;
*/
/*
$tr = new Zend_Mail_Transport_Sendmail('-f'.'apperrors@a19.jp');
Zend_Mail::setDefaultTransport($tr);
*/
require_once 'Zend/Mail.php';
require_once 'Zend/Mime/Part.php';
$mail = new Zend_Mail('iso-2022-jp');
// 元のエンコーディングを保存
$orgEncoding = mb_internal_encoding();
// 変換したい文字列のエンコーディングをセット
mb_internal_encoding('ISO-2022-JP');
$mail->setSubject(strtr(mb_encode_mimeheader(mb_convert_encoding($mailSubject, 'ISO-2022-JP', 'euc-jp'), 'iso-2022-jp'), "\r\n\t", ' '));
if ($mailFrom_1 == '') {
$mail->setFrom($mailFrom);
} else {
$mail->setFrom($mailFrom_2, mb_encode_mimeheader(mb_convert_encoding($mailFrom_1, 'ISO-2022-JP', 'euc-jp'), 'iso-2022-jp'));
}
// $mail->setFrom($mailFrom);
// $mail->setFrom($mailFrom_2, mb_encode_mimeheader(mb_convert_encoding($mailFrom_1, 'ISO-2022-JP', 'euc-jp'), 'iso-2022-jp'));
$mail->addTo($mailTo);
$_file = $_SESSION['SFM']['fileField'];
if ($_file != '' && file_exists($_file)) {
$data = file_get_contents($_file);
$at = new Zend_Mime_Part($data);
$at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = basename($_file);
$mail->addAttachment($at);
}
$mail->setBodyText(mb_convert_encoding($mailMessage, 'ISO-2022-JP', 'euc-jp'), 'ISO-2022-JP', null);
$mail->send();
return true;
}
示例10: attachFile
public function attachFile($filename, $mimetype = "text/csv")
{
// $filepath = Mage::getBaseDir("var") . DS . "20140225081232mediagallery.csv";
$content = is_string($filename) && realpath($filename) ? file_get_contents($filename) : $filename;
$at = new Zend_Mime_Part($content);
$at->filename = basename($filename);
$at->type = $mimetype;
$at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$this->_mail->addAttachment($at);
return $this;
}
示例11: SendEmail
/**
* SendEmail
* Smtp Configuration.
* If you would like to use the smtp authentication, you have to add
* the parameters in the Setting Module of the Control Panel
*
* @param string $from
* @param string or array $to
* @param string $bcc
* @param string $subject
* @param string $body
* @param string $html
* @param string $inreplyto
* @param string/array $attachments
* @return boolean|multitype:unknown NULL
*/
public static function SendEmail($from, $to, $bcc = NULL, $subject, $body, $html = false, $inreplyto = NULL, $attachments = NULL, $replyto = NULL, $cc = null)
{
$transport = null;
$config = array();
$host = Settings::findbyParam('smtp_host');
if (!empty($host)) {
$username = Settings::findbyParam('smtp_user');
$password = Settings::findbyParam('smtp_password');
$port = Settings::findbyParam('smtp_port');
$port = !empty($port) ? $port : 25;
if (!empty($username) && !empty($password)) {
$config = array('auth' => 'login', 'username' => $username, 'password' => $password, 'port' => $port);
}
$transport = new Zend_Mail_Transport_Smtp($host, $config);
}
$mail = new Zend_Mail('UTF-8');
$mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64);
if (!empty($attachments)) {
if (is_array($attachments)) {
foreach ($attachments as $attachment) {
if (file_exists($attachment)) {
$filename = basename($attachment);
// Get the content of the file
$content = file_get_contents($attachment);
// Create the attachment
$zend_attachment = new Zend_Mime_Part($content);
$zend_attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$zend_attachment->encoding = Zend_Mime::ENCODING_BASE64;
$zend_attachment->filename = $filename;
$mail->addAttachment($zend_attachment);
}
}
} else {
if (file_exists($attachments)) {
$filename = basename($attachments);
// Get the content of the file
$content = file_get_contents($attachments);
// Create the attachment
$zend_attachment = new Zend_Mime_Part($content);
$zend_attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$zend_attachment->encoding = Zend_Mime::ENCODING_BASE64;
$zend_attachment->filename = $filename;
$mail->addAttachment($zend_attachment);
}
}
}
if (!empty($inreplyto)) {
$mail->addHeader("In-Reply-To", $inreplyto);
}
if (!empty($replyto)) {
$mail->setReplyTo($replyto);
}
// If the body of the message contains the HTML tags
// we have to override the $html variable in order to send the html message by email
if (self::isHtml($body)) {
$html = true;
}
if ($html) {
$mail->setBodyHtml($body, null, Zend_Mime::ENCODING_8BIT);
} else {
$mail->setBodyText($body);
}
if (is_array($from)) {
$mail->setFrom($from['email'], $from['name']);
} else {
$mail->setFrom($from);
}
// If the $to is a group of emails addresses
if (is_array($to)) {
foreach ($to as $recipient) {
$mail->addTo($recipient);
}
} else {
$mail->addTo($to);
}
if (!empty($bcc)) {
if (is_array($bcc) && count($bcc) > 0) {
foreach ($bcc as $b) {
$mail->addBcc($b);
}
} else {
$mail->addBcc($bcc);
}
}
//.........这里部分代码省略.........
示例12: email_now
function email_now($from_email, $from_name, $to_email, $to_name, $cc_email, $cc_name, $subject, $body, $photos = null)
{
$Mail = new Zend_Mail();
$Mail->setFrom($from_email, $from_name);
$Mail->addTo($to_email, $to_name);
if ('' != $cc_email and $cc_email != $to_email) {
$Mail->addCc($cc_email, $cc_name);
}
$Mail->setSubject($subject);
# $Mail->setBodyText($body);
$Mail->setBodyHtml($body);
if ($photos) {
foreach ($photos as $photo) {
$my_image = file_get_contents(SERVER_NAME . PHOTOS . $photo['id'] . '.' . $photo['ext']);
$at = new Zend_Mime_Part($my_image);
$at->type = 'image/' . $photo['ext'];
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = $photo['file_name'];
$Mail->addAttachment($at);
}
}
//log_sql( null, 'email_now', print_r($Mail, true));
try {
$smtp = get_control_value('System Keys', 'SMTP');
if ($smtp == '') {
$Mail->send();
} else {
$names = explode(';', $smtp);
if (count($names) == 5) {
$config = array('auth' => 'login', 'username' => $names[1], 'password' => $names[2], 'ssl' => $names[3], 'port' => $names[4]);
} else {
if (count($names) == 3) {
$config = array('auth' => 'login', 'username' => $names[1], 'password' => $names[2]);
}
}
if (isset($config)) {
$transport = new Zend_Mail_Transport_Smtp($names[0], $config);
} else {
$transport = new Zend_Mail_Transport_Smtp($names[0]);
}
$Mail->send($transport);
}
} catch (Exception $exp) {
log_sql(null, 'email_now', $exp->getMessage());
return $exp->getMessage();
}
return '';
}
示例13: sendAttachment
/**
* Envia Email com Anexo
*
* @param String $_to
* @param String $_subject
* @param String $_message
* @param Array $_atachment
* array(
* 'file' => '/LOCATION_TO_FILE/FILE.png',
* 'type' => 'image/png',
* 'filename => 'teste.png'
* )
* @param String $_bcc
* @param String $_encodeType
*
* @example
* DBSeller_Helper_Mail_Mail::sendAttachment(
* 'destinatario@email.com',
* 'Assunto',
* 'Mensagem'
* array(
* 'location' => '/local_do_arquivo/meu_arquivo.pdf',
* 'type' => 'application/pdf',
* 'filename' => 'meu_arquivo.pdf'
* )
* );
*
* @return Boolean
*/
public static function sendAttachment($_to = NULL, $_subject = NULL, $_message = NULL, $_atachment = NULL, $_bcc = NULL, $_encodeType = 'utf-8')
{
$_email = new Zend_Mail($_encodeType);
try {
$_attachment = new Zend_Mime_Part(file_get_contents($_atachment['location']));
$_attachment->type = isset($_atachment['type']) ? $_atachment['type'] : 'application/pdf';
$_attachment->disposition = Zend_Mime::DISPOSITION_INLINE;
$_attachment->encoding = Zend_Mime::ENCODING_BASE64;
$_attachment->filename = isset($_atachment['filename']) ? $_atachment['filename'] : 'file.pdf';
// Verifica se foi informado um e-mail de cópia oculta
if (!empty($_bcc)) {
$_email->addBcc($_bcc);
}
// Mail
$_email->addTo($_to);
$_email->setSubject($_subject);
$_email->setBodyHtml($_message);
$_email->addHeader('Priority', 'urgent');
$_email->addHeader('X-Priority', '1');
$_email->addHeader('X-MSMail-Priority', 'High');
$_email->addHeader('Importance', 'High');
$_email->addAttachment($_attachment);
$_email->send();
return TRUE;
} catch (Exception $e) {
return FALSE;
}
}
示例14: explode
// beginning of last month
$toDate = new Zend_Date($fromDate);
$toDate->addMonth(1);
$toDate->addSecond(-1);
$request->setParam('to_date', $toDate->getTimestamp());
// end of last month
// init response
$response = new Zend_Controller_Response_Cli();
// dispatch
$frontController->getDispatcher()->dispatch($request, $response);
// send mail
$config = Zend_Registry::get('config');
$sentToArray = explode(',', $config->settings->monthlyUsageSendTo);
$mail = new Zend_Mail();
$mail->setSubject($view->translate('Monthly Report'));
$mail->setFrom($config->settings->monthlyUsageSendFrom);
$mail->setBodyText($view->translate('CSV file attached.'));
// the attachment
$attachment = new Zend_Mime_Part($response->getBody());
$attachment->type = 'text/csv';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$dateFormat = $view->translate('csv date');
$attachment->filename = 'Usage report ' . $fromDate->toString($dateFormat) . ' to ' . $toDate->toString($dateFormat) . '.csv';
$mail->addAttachment($attachment);
if (count($sentToArray) > 0) {
foreach ($sentToArray as $to) {
$mail->addTo(trim($to));
}
$mail->send();
}
示例15: SendEmail
//.........这里部分代码省略.........
$oMailer->addTo($e, $n);
} else {
$oMailer->addTo($e);
}
}
} else {
if ($toName != $toEmail) {
$oMailer->addTo($toEmail, $toName);
} else {
$oMailer->addTo($toEmail);
}
}
// Resposta do email
if ($replyEmail != $this->_returnPath) {
$oMailer->setReplyTo($replyEmail);
}
// E-mail com cópia oculta
if (is_array($opt) && isset($opt['bcc'])) {
$bcc = $opt['bcc'];
if (is_string($bcc)) {
$oMailer->addBcc($bcc);
} else {
foreach ($bcc as $email) {
$oMailer->addBcc($email);
}
}
}
// Email com cópia
if (is_array($opt) && isset($opt['cc'])) {
$cc = $opt['cc'];
if (is_string($cc)) {
$oMailer->addCc($cc);
} else {
foreach ($cc as $name => $email) {
$oMailer->addCc($email, $name);
}
}
}
// Assunto do E-mail
$oMailer->setSubject($subject);
// Verifica se há headers para serem adicionados ao email
if (is_array($opt) && isset($opt['headers']) && is_array($opt['headers'])) {
foreach ($opt['headers'] as $h => $v) {
$oMailer->addHeader($h, $v);
}
}
// Cria a mensagem
$msgText = null;
$msgHtml = null;
if (is_string($message) && !isset($opt['html'])) {
$msgText = $message;
} elseif (is_string($message) && isset($opt['html'])) {
$msgHtml = $message;
$oMailer->setBodyHtml($message);
} elseif (is_array($message)) {
if (isset($message['text'])) {
$msgText = $message['text'];
}
if (isset($message['html'])) {
$msgHtml = $message['html'];
}
}
// Cria o TXT a partir do HTML
if (is_null($msgText) && !is_null($msgHtml)) {
$msgText = $this->_extractText($msgHtml);
}
if (!is_null($msgText)) {
$oMailer->setBodyText($msgText);
}
if (!is_null($msgHtml)) {
$oMailer->setBodyHtml($msgHtml);
}
if (is_null($msgText) && is_null($msgHtml)) {
die("Não foi possível definir o corpo da mensagem.");
}
// Verifica se tem anexos
if (is_array($opt) && isset($opt['anexos']) && is_array($opt['anexos'])) {
foreach ($opt['anexos'] as $filename => $f) {
// Verifica se é um arquivou o anexo na memória
if ($f instanceof Zend_Mime_Part) {
if (is_null($f->disposition)) {
$f->disposition = Zend_Mime::DISPOSITION_INLINE;
}
$oMailer->addAttachment($f);
// Verifica se o arquivo existe
} elseif (is_string($f) && file_exists($f)) {
// Verifica se deve trocar o nome do arquivo
if (is_numeric($filename)) {
$filename = array_pop(explode(DIRECTORY_SEPARATOR . $f));
}
// Coloca o anexo na mensagem
$file = file_get_contents($f);
$at = $oMailer->createAttachment($file);
$at->filename = $filename;
}
}
}
//Envia o email
$oMailer->send();
}