本文整理汇总了PHP中Email::attachFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Email::attachFile方法的具体用法?PHP Email::attachFile怎么用?PHP Email::attachFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Email
的用法示例。
在下文中一共展示了Email::attachFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSendHTML
public function testSendHTML()
{
// Set custom $project - used in email headers
global $project;
$oldProject = $project;
$project = 'emailtest';
Email::set_mailer(new EmailTest_Mailer());
$email = new Email('from@example.com', 'to@example.com', 'Test send plain', 'Testing Email->sendPlain()', null, 'cc@example.com', 'bcc@example.com');
$email->attachFile(__DIR__ . '/fixtures/attachment.txt', null, 'text/plain');
$email->addCustomHeader('foo', 'bar');
$sent = $email->send(123);
// Restore old project name after sending
$project = $oldProject;
$this->assertEquals('to@example.com', $sent['to']);
$this->assertEquals('from@example.com', $sent['from']);
$this->assertEquals('Test send plain', $sent['subject']);
$this->assertContains('Testing Email->sendPlain()', $sent['content']);
$this->assertNull($sent['plaincontent']);
$this->assertEquals(array(0 => array('contents' => 'Hello, I\'m a text document.', 'filename' => 'attachment.txt', 'mimetype' => 'text/plain')), $sent['files']);
$this->assertEquals(array('foo' => 'bar', 'X-SilverStripeMessageID' => 'emailtest.123', 'X-SilverStripeSite' => 'emailtest', 'Cc' => 'cc@example.com', 'Bcc' => 'bcc@example.com'), $sent['customheaders']);
}
示例2: process
public function process()
{
$service = singleton('QueuedJobService');
$report = $this->getReport();
if (!$report) {
$this->currentStep++;
$this->isComplete = true;
return;
}
$clone = clone $report;
$clone->GeneratedReportTitle = $report->ScheduledTitle;
$result = $clone->prepareAndGenerate();
if ($report->ScheduleEvery) {
if ($report->ScheduleEvery == 'Custom') {
$interval = $report->ScheduleEveryCustom;
} else {
$interval = $report->ScheduleEvery;
}
$next = $service->queueJob(new ScheduledReportJob($report, $this->timesGenerated + 1), date('Y-m-d H:i:s', strtotime("+1 {$interval}")));
$report->QueuedJobID = $next;
} else {
$report->Scheduled = false;
$report->QueuedJobID = 0;
}
$report->write();
if ($report->EmailScheduledTo) {
$email = new Email();
$email->setTo($report->EmailScheduledTo);
$email->setSubject($result->Title);
$email->setBody(_t('ScheduledReportJob.SEE_ATTACHED_REPORT', 'Please see the attached report file'));
$email->attachFile($result->PDFFile()->getFullPath(), $result->PDFFile()->Filename, 'application/pdf');
$email->send();
}
$this->currentStep++;
$this->isComplete = true;
}
示例3: generateEmailObject
/**
* Generate the e-mail object and return it
* @param object
* @param array
* @return object
*/
protected function generateEmailObject(Database_Result $objNewsletter, $arrAttachments)
{
$objEmail = new Email();
$objEmail->from = $objNewsletter->sender;
$objEmail->subject = $objNewsletter->subject;
// Add sender name
if (strlen($objNewsletter->senderName)) {
$objEmail->fromName = $objNewsletter->senderName;
}
$objEmail->embedImages = !$objNewsletter->externalImages;
$objEmail->logFile = 'newsletter_' . $objNewsletter->id . '.log';
// Attachments
if (is_array($arrAttachments) && count($arrAttachments) > 0) {
foreach ($arrAttachments as $strAttachment) {
$objEmail->attachFile(TL_ROOT . '/' . $strAttachment);
}
}
return $objEmail;
}
示例4: onSubmitCbSendEmail
/**
* onsubmit_callback
* send email
*/
public function onSubmitCbSendEmail()
{
// the save-button is a fileupload-button
if (!\Input::post('saveNclose')) {
return;
}
$email = new Email();
$fromMail = $this->User->email;
$subject = \Input::post('subject');
$email->replyTo($fromMail);
$email->from = $fromMail;
$email->subject = $subject;
$email->html = base64_decode($_POST['content']);
//save attachment
$arrFiles = array();
$db = $this->Database->prepare('SELECT attachment FROM tl_be_email WHERE id=?')->execute(\Input::get('id'));
// Attachment
if ($db->attachment != '') {
$arrFiles = unserialize($db->attachment);
foreach ($arrFiles as $filekey => $filename) {
if (file_exists(TL_ROOT . '/' . BE_EMAIL_UPLOAD_DIR . '/' . $filekey)) {
$this->Files->copy(BE_EMAIL_UPLOAD_DIR . '/' . $filekey, 'system/tmp/' . $filename);
$email->attachFile(TL_ROOT . '/system/tmp/' . $filename);
}
}
}
// Cc
$cc_recipients = array_unique($this->validateEmailAddresses(\Input::post('recipientsCc'), 'recipientsCc'));
if (count($cc_recipients)) {
$email->sendCc($cc_recipients);
}
// Bcc
$bcc_recipients = array_unique($this->validateEmailAddresses(\Input::post('recipientsBcc'), 'recipientsBcc'));
if (count($bcc_recipients)) {
$email->sendBcc($bcc_recipients);
}
// To
$recipients = array_unique($this->validateEmailAddresses(\Input::post('recipientsTo'), 'recipientsTo'));
if (count($recipients)) {
$email->sendTo($recipients);
}
// Delete attachment from server
foreach ($arrFiles as $filekey => $filename) {
// delete file in the tmp-folder
if (is_file(TL_ROOT . '/system/tmp/' . $filename)) {
$this->Files->delete('/system/tmp/' . $filename);
}
}
}
示例5: mail
//.........这里部分代码省略.........
$sender = $this->replaceInsertTags($sender);
}
$confEmail = new Email();
$confEmail->from = $sender;
if (strlen($senderName)) {
$confEmail->fromName = $senderName;
}
$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);
// did the saved value result in an array?
if (is_array($arrCustomAttachments)) {
foreach ($arrCustomAttachments as $strFile) {
// does the file really exist?
if (is_file(TL_ROOT . '/' . $strFile)) {
// can we read the file?
if (is_readable(TL_ROOT . '/' . $strFile)) {
$objFile = new File($strFile);
if ($objFile->size) {
$attachments[] = $objFile->value;
}
}
}
}
}
}
}
if (is_array($attachments) && count($attachments) > 0) {
foreach ($attachments as $attachment) {
$confEmail->attachFile(TL_ROOT . '/' . $attachment);
}
}
if ($dirImages != '') {
$confEmail->imageDir = $dirImages;
}
if ($messageText != '') {
$messageText = html_entity_decode($messageText, ENT_QUOTES, $GLOBALS['TL_CONFIG']['characterSet']);
$messageText = strip_tags($messageText);
$confEmail->text = $messageText;
}
if ($messageHtml != '') {
$confEmail->html = $messageHtml;
}
// Send Mail
if (strlen($this->Input->get('token')) && $this->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 (count($arrRecipient) > 0) {
$arrSentTo = array();
foreach ($arrRecipient 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];
}
}
示例6: attachFiles
/**
* Attaches the given files to the given email.
*
* @param Email $email Email
* @param array $attachments Attachments
*
* @return void
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 26.08.2011
*/
protected static function attachFiles(Email $email, $attachments)
{
if (!is_null($attachments)) {
if (is_array($attachments)) {
foreach ($attachments as $attachment) {
if (is_array($attachment)) {
$filename = $attachment['filename'];
$attachedFilename = array_key_exists('attachedFilename', $attachment) ? $attachment['attachedFilename'] : basename($filename);
$mimetype = array_key_exists('mimetype', $attachment) ? $attachment['mimetype'] : null;
} else {
$filename = $attachment;
$attachedFilename = basename($attachment);
$mimetype = null;
}
$email->attachFile($filename, $attachedFilename, $mimetype);
}
} else {
$email->attachFile($attachments, basename($attachments));
}
}
}
示例7: process
public function process()
{
self::$config = $this->config();
if (!self::$config->wkHtmlToPdfPath) {
throw new Exception("You must provide a path for WkHtmlToPdf in your sites configuration.");
}
if (!self::$config->emailAddress) {
throw new Exception("You must provide an email address to send from in your sites configuration.");
}
increase_memory_limit_to('1024M');
set_time_limit(0);
$sites = LinkCheckSite::get();
$outputDir = BASE_PATH . DIRECTORY_SEPARATOR . "silverstripe-linkcheck/runs/";
$filesCreated = array();
// build the crawler
chdir(__DIR__ . "/../thirdparty");
exec("javac " . self::$crawler . " " . self::$linkStats . " && " . "javac " . self::$linkProject);
if ($sites) {
foreach ($sites as $site) {
echo "Checking " . $site->SiteURL . "\r\n";
$url = $site->SiteURL;
// if the output directory doesn't exist for the run, create it
if (!file_exists($outputDir . str_replace("http://", "", $url))) {
mkdir($outputDir . str_replace("http://", "", $url));
}
$filename = date("Y-m-d") . '-' . rand(0, 1000) . ".html";
$filepath = $outputDir . str_replace("http://", "", $url) . '/';
// execute the crawler
exec("java Project {$url} " . $filepath . $filename . " 10 1000");
$filesCreated[$site->ID]['FilePath'] = $filepath;
$filesCreated[$site->ID]['FileName'] = $filename;
$filesCreated[$site->ID]['SiteName'] = $site->SiteName;
$filesCreated[$site->ID]['ID'] = $site->ID;
$filesCreated[$site->ID]['URL'] = $url;
$emailRecipients = $site->EmailRecipients();
if ($emailRecipients) {
foreach ($emailRecipients as $recipient) {
$filesCreated[$site->ID]['Email'][] = $recipient->Email;
}
}
}
foreach ($filesCreated as $file) {
Folder::find_or_make("LinkCheck" . DIRECTORY_SEPARATOR . $file['SiteName'] . DIRECTORY_SEPARATOR);
$pdfPath = "assets" . DIRECTORY_SEPARATOR . "LinkCheck" . DIRECTORY_SEPARATOR . $file['SiteName'] . DIRECTORY_SEPARATOR;
$pdfFullPath = BASE_PATH . DIRECTORY_SEPARATOR . $pdfPath;
$pdfName = str_replace("html", "pdf", $file['FileName']);
$generator = new WkHtml\Generator(new \Knp\Snappy\Pdf(self::$config->wkHtmlToPdfPath), new WkHtml\Input\String(file_get_contents($file['FilePath'] . $file['FileName'])), new WkHtml\Output\File($pdfFullPath . $pdfName, 'application/pdf'));
$generator->process();
$site = LinkCheckSite::get()->byID($file['ID']);
$pdfUpload = new File();
$pdfUpload->Title = $file['SiteName'] . '-' . $pdfName;
$pdfUpload->Filename = $pdfPath . $pdfName;
$pdfUpload->write();
$linkCheckRun = new LinkCheckRun();
$linkCheckRun->LinkCheckFileID = $pdfUpload->ID;
$linkCheckRun->LinkCheckSiteID = $site->ID;
$linkCheckRun->write();
$site->LinkCheckRuns()->add($linkCheckRun);
foreach ($file['Email'] as $emailAddress) {
$email = new Email();
$email->to = $emailAddress;
$email->from = $this->config()->emailAddress;
$email->subject = $file['SiteName'] . " link check run";
$email->body = "Site Link Check Run for {$file['URL']} on " . date("Y/m/d");
$email->attachFile($pdfPath . $pdfName, "linkcheck.pdf");
$email->send();
}
unlink($file['FilePath'] . $file['FileName']);
}
}
}