当前位置: 首页>>代码示例>>PHP>>正文


PHP Email::attachFileFromString方法代码示例

本文整理汇总了PHP中Email::attachFileFromString方法的典型用法代码示例。如果您正苦于以下问题:PHP Email::attachFileFromString方法的具体用法?PHP Email::attachFileFromString怎么用?PHP Email::attachFileFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Email的用法示例。


在下文中一共展示了Email::attachFileFromString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAttachFiles

 public function testAttachFiles()
 {
     $email = new Email();
     $email->attachFileFromString('foo bar', 'foo.txt', 'text/plain');
     $email->attachFile(__DIR__ . '/fixtures/attachment.txt', null, 'text/plain');
     $this->assertEquals(array('contents' => 'foo bar', 'filename' => 'foo.txt', 'mimetype' => 'text/plain'), $email->attachments[0], 'File is attached correctly from string');
     $this->assertEquals(array('contents' => 'Hello, I\'m a text document.', 'filename' => 'attachment.txt', 'mimetype' => 'text/plain'), $email->attachments[1], 'File is attached correctly from file');
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:8,代码来源:EmailTest.php

示例2: processFormData

 /**
  * Process form data, store it in the session and redirect to the jumpTo page
  *
  * @param array $arrSubmitted
  * @param array $arrLabels
  * @param array $arrFields
  */
 protected function processFormData($arrSubmitted, $arrLabels, $arrFields)
 {
     // HOOK: prepare form data callback
     if (isset($GLOBALS['TL_HOOKS']['prepareFormData']) && is_array($GLOBALS['TL_HOOKS']['prepareFormData'])) {
         foreach ($GLOBALS['TL_HOOKS']['prepareFormData'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($arrSubmitted, $arrLabels, $arrFields, $this);
         }
     }
     // Send form data via e-mail
     if ($this->sendViaEmail) {
         $keys = array();
         $values = array();
         $fields = array();
         $message = '';
         foreach ($arrSubmitted as $k => $v) {
             if ($k == 'cc') {
                 continue;
             }
             $v = deserialize($v);
             // Skip empty fields
             if ($this->skipEmpty && !is_array($v) && !strlen($v)) {
                 continue;
             }
             // Add field to message
             $message .= (isset($arrLabels[$k]) ? $arrLabels[$k] : ucfirst($k)) . ': ' . (is_array($v) ? implode(', ', $v) : $v) . "\n";
             // Prepare XML file
             if ($this->format == 'xml') {
                 $fields[] = array('name' => $k, 'values' => is_array($v) ? $v : array($v));
             }
             // Prepare CSV file
             if ($this->format == 'csv') {
                 $keys[] = $k;
                 $values[] = is_array($v) ? implode(',', $v) : $v;
             }
         }
         $recipients = \StringUtil::splitCsv($this->recipient);
         // Format recipients
         foreach ($recipients as $k => $v) {
             $recipients[$k] = str_replace(array('[', ']', '"'), array('<', '>', ''), $v);
         }
         $email = new \Email();
         // Get subject and message
         if ($this->format == 'email') {
             $message = $arrSubmitted['message'];
             $email->subject = $arrSubmitted['subject'];
         }
         // Set the admin e-mail as "from" address
         $email->from = $GLOBALS['TL_ADMIN_EMAIL'];
         $email->fromName = $GLOBALS['TL_ADMIN_NAME'];
         // Get the "reply to" address
         if (strlen(\Input::post('email', true))) {
             $replyTo = \Input::post('email', true);
             // Add name
             if (strlen(\Input::post('name'))) {
                 $replyTo = '"' . \Input::post('name') . '" <' . $replyTo . '>';
             }
             $email->replyTo($replyTo);
         }
         // Fallback to default subject
         if (!strlen($email->subject)) {
             $email->subject = $this->replaceInsertTags($this->subject, false);
         }
         // Send copy to sender
         if (strlen($arrSubmitted['cc'])) {
             $email->sendCc(\Input::post('email', true));
             unset($_SESSION['FORM_DATA']['cc']);
         }
         // Attach XML file
         if ($this->format == 'xml') {
             /** @var \FrontendTemplate|object $objTemplate */
             $objTemplate = new \FrontendTemplate('form_xml');
             $objTemplate->fields = $fields;
             $objTemplate->charset = \Config::get('characterSet');
             $email->attachFileFromString($objTemplate->parse(), 'form.xml', 'application/xml');
         }
         // Attach CSV file
         if ($this->format == 'csv') {
             $email->attachFileFromString(\StringUtil::decodeEntities('"' . implode('";"', $keys) . '"' . "\n" . '"' . implode('";"', $values) . '"'), 'form.csv', 'text/comma-separated-values');
         }
         $uploaded = '';
         // Attach uploaded files
         if (!empty($_SESSION['FILES'])) {
             foreach ($_SESSION['FILES'] as $file) {
                 // Add a link to the uploaded file
                 if ($file['uploaded']) {
                     $uploaded .= "\n" . \Environment::get('base') . str_replace(TL_ROOT . '/', '', dirname($file['tmp_name'])) . '/' . rawurlencode($file['name']);
                     continue;
                 }
                 $email->attachFileFromString(file_get_contents($file['tmp_name']), $file['name'], $file['type']);
             }
         }
         $uploaded = strlen(trim($uploaded)) ? "\n\n---\n" . $uploaded : '';
//.........这里部分代码省略.........
开发者ID:jamesdevine,项目名称:core-bundle,代码行数:101,代码来源:Form.php

示例3: postmessage

 public function postmessage($data, $form)
 {
     $signature = PostmarkSignature::get()->byID($data['FromID']);
     PostmarkMailer::RecordEmails(true);
     PostmarkMailer::ReplyToMessageID($data['InReplyToID']);
     $clients = PostmarkHelper::client_list()->filter('ID', $data['ToMemberID']);
     foreach ($clients as $client) {
         $email = new Email($signature->Email, $client->Email, $data['Subject'], PostmarkHelper::MergeEmailText($data['Body'], $client));
         for ($i = 1; $i <= 5; $i += 1) {
             $strKey = 'Attachment_' . $i;
             if (isset($_FILES[$strKey]) && $_FILES[$strKey]['tmp_name']) {
                 $contents = file_get_contents($_FILES[$strKey]['tmp_name']);
                 if (strlen($contents)) {
                     $email->attachFileFromString($contents, $_FILES[$strKey]['name']);
                 }
             }
         }
         $this->extend('updatePostmessage', $email, $data);
         $email->setTemplate('NewsletterTemplate');
         $email->send();
     }
     PostmarkMailer::RecordEmails(false);
     PostmarkMailer::ReplyToMessageID(0);
 }
开发者ID:bueckl,项目名称:postmarkedapp,代码行数:24,代码来源:PostmarkAdmin.php

示例4: processSubmittedData


//.........这里部分代码省略.........
                 if (!empty($arrCustomAttachments)) {
                     foreach ($arrCustomAttachments as $varFile) {
                         $objFileModel = \FilesModel::findById($varFile);
                         if ($objFileModel !== null) {
                             $objFile = new \File($objFileModel->path);
                             if ($objFile->size) {
                                 $objMailProperties->attachments[TL_ROOT . '/' . $objFile->path] = array('file' => TL_ROOT . '/' . $objFile->path, 'name' => $objFile->basename, 'mime' => $objFile->mime);
                             }
                         }
                     }
                 }
             }
         }
         $objMailProperties->subject = \String::decodeEntities($arrForm['confirmationMailSubject']);
         $objMailProperties->messageText = \String::decodeEntities($arrForm['confirmationMailText']);
         $objMailProperties->messageHtmlTmpl = $arrForm['confirmationMailTemplate'];
         // Replace Insert tags and conditional tags
         $objMailProperties = $this->Formdata->prepareMailData($objMailProperties, $arrSubmitted, $arrFiles, $arrForm, $arrFormFields);
         // Send Mail
         $blnConfirmationSent = false;
         if (!empty($objMailProperties->recipients)) {
             $objMail = new \Email();
             $objMail->from = $objMailProperties->sender;
             if (!empty($objMailProperties->senderName)) {
                 $objMail->fromName = $objMailProperties->senderName;
             }
             if (!empty($objMailProperties->replyTo)) {
                 $objMail->replyTo($objMailProperties->replyTo);
             }
             $objMail->subject = $objMailProperties->subject;
             if (!empty($objMailProperties->attachments)) {
                 foreach ($objMailProperties->attachments as $strFile => $varParams) {
                     $strContent = file_get_contents($varParams['file'], false);
                     $objMail->attachFileFromString($strContent, $varParams['name'], $varParams['mime']);
                 }
             }
             if (!empty($objMailProperties->messageText)) {
                 $objMail->text = $objMailProperties->messageText;
             }
             if (!empty($objMailProperties->messageHtml)) {
                 $objMail->html = $objMailProperties->messageHtml;
             }
             foreach ($objMailProperties->recipients as $recipient) {
                 $objMail->sendTo($recipient);
                 $blnConfirmationSent = true;
             }
         }
         if ($blnConfirmationSent && isset($intNewId) && intval($intNewId) > 0) {
             $arrUpd = array('confirmationSent' => '1', 'confirmationDate' => $timeNow);
             $res = \Database::getInstance()->prepare("UPDATE tl_formdata %s WHERE id=?")->set($arrUpd)->execute($intNewId);
         }
     }
     // Information (formatted) Mail
     if ($blnFEedit && !$arrForm['sendFormattedMailOnFrontendEditing']) {
         $arrForm['sendFormattedMail'] = false;
     }
     if ($arrForm['sendFormattedMail']) {
         $objMailProperties = new \stdClass();
         $objMailProperties->subject = '';
         $objMailProperties->sender = '';
         $objMailProperties->senderName = '';
         $objMailProperties->replyTo = '';
         $objMailProperties->recipients = array();
         $objMailProperties->messageText = '';
         $objMailProperties->messageHtmlTmpl = '';
         $objMailProperties->messageHtml = '';
开发者ID:Jobu,项目名称:core,代码行数:67,代码来源:FormdataProcessor.php

示例5: processSubmittedData


//.........这里部分代码省略.........
         }
         $confEmail = new Email();
         $confEmail->from = $sender;
         if (strlen($senderName)) {
             $confEmail->fromName = $senderName;
         }
         if (strlen($replyTo)) {
             $confEmail->replyTo($replyTo);
         }
         $confEmail->subject = $subject;
         // Thanks to Torben Schwellnus
         // check if we want custom attachments...
         if ($arrForm['addConfirmationMailAttachments']) {
             // check if we have custom attachments...
             if ($arrForm['confirmationMailAttachments']) {
                 $arrCustomAttachments = deserialize($arrForm['confirmationMailAttachments'], true);
                 if (is_array($arrCustomAttachments)) {
                     foreach ($arrCustomAttachments as $strFile) {
                         if (is_file($strFile)) {
                             if (is_readable($strFile)) {
                                 $objFile = new File($strFile);
                                 if ($objFile->size) {
                                     $attachments[$objFile->value] = array('file' => TL_ROOT . '/' . $objFile->value, 'name' => $objFile->basename, 'mime' => $objFile->mime);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (is_array($attachments) && count($attachments) > 0) {
             foreach ($attachments as $strFile => $varParams) {
                 $strContent = file_get_contents($strFile, false);
                 $confEmail->attachFileFromString($strContent, $varParams['name'], $varParams['mime']);
             }
         }
         if ($dirImages != '') {
             $confEmail->imageDir = $dirImages;
         }
         if ($messageText != '') {
             $confEmail->text = $messageText;
         }
         if ($messageHtml != '') {
             $confEmail->html = $messageHtml;
         }
         // Send e-mail
         $blnConfirmationSent = false;
         if (count($arrRecipient) > 0) {
             foreach ($arrRecipient as $recipient) {
                 if (strlen($recipient)) {
                     $recipient = $this->replaceInsertTags($recipient);
                     $recipient = str_replace(array('[', ']'), array('<', '>'), $recipient);
                     $recipientName = '';
                     if (strpos($recipient, '<') > 0) {
                         preg_match('/(.*)?<(\\S*)>/si', $recipient, $parts);
                         $recipientName = trim($parts[1]);
                         $recipient = strlen($recipientName) ? $recipientName . ' <' . $parts[2] . '>' : $parts[2];
                     }
                 }
                 $confEmail->sendTo($recipient);
                 $blnConfirmationSent = true;
             }
         }
         if ($blnConfirmationSent && isset($intNewId) && intval($intNewId) > 0) {
             $arrUpd = array('confirmationSent' => '1', 'confirmationDate' => $timeNow);
             $res = $this->Database->prepare("UPDATE tl_formdata %s WHERE id=?")->set($arrUpd)->execute($intNewId);
开发者ID:jens-wetzel,项目名称:use2,代码行数:67,代码来源:Efp.php

示例6: sendEmail

 protected function sendEmail($what, Member $member, array $data = [])
 {
     $profiledConfig = ProfiledConfig::current_profiled_config();
     $templateData = array_merge(['Member' => $member], $data);
     $memberEmailTemplate = self::MemberEmailPrefix . strtolower($what);
     if (SSViewer::hasTemplate($memberEmailTemplate)) {
         // send email to member from ProfiledConfig.SendEmailFrom to Member.Email
         $emailMember = new Email($profiledConfig->getProfiledSender('Member'), $member->Email, $profiledConfig->getProfiledEmailSubject('Member', $what));
         $emailMember->setTemplate($memberEmailTemplate);
         $emailMember->populateTemplate($templateData);
         $emailMember->send();
     }
     $adminEmailTemplate = self::AdminEmailPrefix . strtolower($what);
     if (SSViewer::hasTemplate([$adminEmailTemplate])) {
         // send admin email from either Member.Email or ProfiledConfig.SendEmailFrom to Profiled.AdminEmail
         $emailAdmin = new Email($profiledConfig->getProfiledSender('Admin', $member->Email), $profiledConfig->getAdminEmail(), $profiledConfig->getProfiledEmailSubject('Admin', $what));
         $emailAdmin->setTemplate($adminEmailTemplate);
         $emailAdmin->populateTemplate($templateData);
         // save body to attach to admin email
         if (isset($emailMember)) {
             $emailAdmin->attachFileFromString($emailMember->Body(), $member->Email . "_registration.txt");
         }
         $emailAdmin->send();
     }
 }
开发者ID:CrackerjackDigital,项目名称:silverstripe-profiled,代码行数:25,代码来源:Controller.php

示例7: processFormData

 /**
  * Process form data, store it in the session and redirect to the jumpTo page
  * @param array
  * @param array
  */
 protected function processFormData($arrSubmitted, $arrLabels)
 {
     // Send form data via e-mail
     if ($this->sendViaEmail) {
         $this->import('String');
         $keys = array();
         $values = array();
         $fields = array();
         $message = '';
         foreach ($arrSubmitted as $k => $v) {
             if ($k == 'cc') {
                 continue;
             }
             $v = deserialize($v);
             // Skip empty fields
             if ($this->skipEmpty && !is_array($v) && !strlen($v)) {
                 continue;
             }
             // Add field to message
             $message .= (isset($arrLabels[$k]) ? $arrLabels[$k] : ucfirst($k)) . ': ' . (is_array($v) ? implode(', ', $v) : $v) . "\n";
             // Prepare XML file
             if ($this->format == 'xml') {
                 $fields[] = array('name' => $k, 'values' => is_array($v) ? $v : array($v));
             }
             // Prepare CSV file
             if ($this->format == 'csv') {
                 $keys[] = $k;
                 $values[] = is_array($v) ? implode(',', $v) : $v;
             }
         }
         $recipients = $this->String->splitCsv($this->recipient);
         // Format recipients
         foreach ($recipients as $k => $v) {
             $recipients[$k] = str_replace(array('[', ']', '"'), array('<', '>', ''), $v);
         }
         $email = new Email();
         // Get subject and message
         if ($this->format == 'email') {
             $message = $arrSubmitted['message'];
             $email->subject = $arrSubmitted['subject'];
         }
         // Set the admin e-mail as "from" address
         $email->from = $GLOBALS['TL_ADMIN_EMAIL'];
         $email->fromName = $GLOBALS['TL_ADMIN_NAME'];
         // Get the "reply to" address
         if (strlen($this->Input->post('email', true))) {
             $replyTo = $this->Input->post('email', true);
             // Add name
             if (strlen($this->Input->post('name'))) {
                 $replyTo = '"' . $this->Input->post('name') . '" <' . $replyTo . '>';
             }
             $email->replyTo($replyTo);
         }
         // Fallback to default subject
         if (!strlen($email->subject)) {
             $email->subject = $this->replaceInsertTags($this->subject);
         }
         // Send copy to sender
         if (strlen($arrSubmitted['cc'])) {
             $email->sendCc($this->Input->post('email', true));
             unset($_SESSION['FORM_DATA']['cc']);
         }
         // Attach XML file
         if ($this->format == 'xml') {
             $objTemplate = new FrontendTemplate('form_xml');
             $objTemplate->fields = $fields;
             $objTemplate->charset = $GLOBALS['TL_CONFIG']['characterSet'];
             $email->attachFileFromString($objTemplate->parse(), 'form.xml', 'application/xml');
         }
         // Attach CSV file
         if ($this->format == 'csv') {
             $email->attachFileFromString($this->String->decodeEntities('"' . implode('";"', $keys) . '"' . "\n" . '"' . implode('";"', $values) . '"'), 'form.csv', 'text/comma-separated-values');
         }
         $uploaded = '';
         // Attach uploaded files
         if (count($_SESSION['FILES'])) {
             foreach ($_SESSION['FILES'] as $file) {
                 // Add a link to the uploaded file
                 if ($file['uploaded']) {
                     $uploaded .= "\n" . $this->Environment->base . str_replace(TL_ROOT . '/', '', dirname($file['tmp_name'])) . '/' . rawurlencode($file['name']);
                     continue;
                 }
                 $email->attachFileFromString(file_get_contents($file['tmp_name']), $file['name'], $file['type']);
             }
         }
         $uploaded = strlen(trim($uploaded)) ? "\n\n---\n" . $uploaded : '';
         // Send e-mail
         $email->text = $this->String->decodeEntities(trim($message)) . $uploaded . "\n\n";
         $email->sendTo($recipients);
     }
     // Store values in the database
     if ($this->storeValues && strlen($this->targetTable)) {
         $arrSet = array();
         // Add timestamp
         if ($this->Database->fieldExists('tstamp', $this->targetTable)) {
//.........这里部分代码省略.........
开发者ID:Juuro,项目名称:Dreamapp-Website,代码行数:101,代码来源:Form.php

示例8: mail


//.........这里部分代码省略.........
        }
        $objMailProperties->recipients = $arrRecipient;
        // Check if we want custom attachments... (Thanks to Torben Schwellnus)
        if ($arrForm['addConfirmationMailAttachments']) {
            if ($arrForm['confirmationMailAttachments']) {
                $arrCustomAttachments = deserialize($arrForm['confirmationMailAttachments'], true);
                if (!empty($arrCustomAttachments)) {
                    foreach ($arrCustomAttachments as $varFile) {
                        $objFileModel = \FilesModel::findById($varFile);
                        if ($objFileModel !== null) {
                            $objFile = new \File($objFileModel->path, true);
                            if ($objFile->size) {
                                $objMailProperties->attachments[TL_ROOT . '/' . $objFile->path] = array('file' => TL_ROOT . '/' . $objFile->path, 'name' => $objFile->basename, 'mime' => $objFile->mime);
                            }
                        }
                    }
                }
            }
        }
        $objMailProperties->subject = \String::decodeEntities($arrForm['confirmationMailSubject']);
        $objMailProperties->messageText = \String::decodeEntities($arrForm['confirmationMailText']);
        $objMailProperties->messageHtmlTmpl = $arrForm['confirmationMailTemplate'];
        // Replace Insert tags and conditional tags
        $objMailProperties = $this->Formdata->prepareMailData($objMailProperties, $arrSubmitted, $arrFiles, $arrForm, $arrFormFields);
        $objEmail = new \Email();
        $objEmail->from = $objMailProperties->sender;
        if (!empty($objMailProperties->senderName)) {
            $objEmail->fromName = $objMailProperties->senderName;
        }
        $objEmail->subject = $objMailProperties->subject;
        if (!empty($objMailProperties->attachments)) {
            foreach ($objMailProperties->attachments as $strFile => $varParams) {
                $strContent = file_get_contents($varParams['file'], false);
                $objEmail->attachFileFromString($strContent, $varParams['name'], $varParams['mime']);
            }
        }
        if (!empty($objMailProperties->messageText)) {
            $objEmail->text = $objMailProperties->messageText;
        }
        if (!empty($objMailProperties->messageHtml)) {
            $objEmail->html = $objMailProperties->messageHtml;
        }
        // Send Mail
        if (strlen(\Input::get('token')) && \Input::get('token') == $this->Session->get('fd_mail_send')) {
            $this->Session->set('fd_mail_send', null);
            $blnSend = true;
            $blnConfirmationSent = false;
            if ($blnSend) {
                // Send e-mail
                if (!empty($objMailProperties->recipients)) {
                    foreach ($objMailProperties->recipients as $recipient) {
                        if (strlen($recipient)) {
                            $recipient = str_replace(array('[', ']'), array('<', '>'), $recipient);
                            $recipientName = '';
                            if (strpos($recipient, '<') > 0) {
                                preg_match('/(.*)?<(\\S*)>/si', $recipient, $parts);
                                $recipientName = trim($parts[1]);
                                $recipient = strlen($recipientName) ? $recipientName . ' <' . $parts[2] . '>' : $parts[2];
                            }
                        }
                        $objEmail->sendTo($recipient);
                        $blnConfirmationSent = true;
                        \Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_formdata']['mail_sent'], str_replace(array('<', '>'), array('[', ']'), $recipient)));
                    }
                }
                if ($blnConfirmationSent && isset($this->intId) && intval($this->intId) > 0) {
开发者ID:byteworks-ch,项目名称:contao-efg,代码行数:67,代码来源:DC_Formdata.php


注:本文中的Email::attachFileFromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。