本文整理汇总了PHP中Swift_Attachment类的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Attachment类的具体用法?PHP Swift_Attachment怎么用?PHP Swift_Attachment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Swift_Attachment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _swiftMail
protected function _swiftMail($to, $from, $subject, $message, $attachments = [], $html = true)
{
$mailer = $this->__getSwiftMailer($from);
if (is_array($to) && isset($to['email'])) {
if (isset($to['name'])) {
$to = [$to['email'] => $to['name']];
} else {
$to = $to['email'];
}
}
$mail = new \Swift_Message();
$mail->setSubject($subject)->setFrom($from['email'], $from['name'])->setTo($to);
if (isset($from['reply-to'])) {
if (is_array($from['reply-to']) && isset($from['email'])) {
$mail->setReplyTo($from['reply-to']['email'], $from['reply-to']['name']);
} else {
$mail->setReplyTo($from['reply-to']);
}
}
$mail->setBody($message, $html ? 'text/html' : 'text/plain');
foreach ($attachments as $attachment) {
$mail->attach(\Swift_Attachment::fromPath($attachment));
}
return $mailer->send($mail);
}
示例2: sendBasic
/**
*
* @param array $o
* @throws InvalidArgumentException
* @return multitype:NULL string |multitype:NULL |number
*
*/
public function sendBasic(smMailMessage $smMailMessage, array $options)
{
$this->smMailMessage = $smMailMessage;
$message = Swift_Message::newInstance();
$this->setSMTPData($message, $options['account']);
$this->feedAddress($message, 'to', $this->smMailMessage->to);
$this->feedAddress($message, 'cc', $this->smMailMessage->cc);
$this->feedAddress($message, 'bcc', $this->smMailMessage->bcc);
$message->setFrom(array($smMailMessage->from => $smMailMessage->fromName ? $smMailMessage->fromName : $this->from));
$message->setSender($smMailMessage->sender);
$message->addReplyTo($this->smMailMessage->replyTo);
$message->setSubject($smMailMessage->subject);
$headers = $message->getHeaders();
if (count($this->customheaders) > 0) {
foreach ($this->customheaders as $kc => $vc) {
$headers->addTextHeader(array($kc, $vc));
}
}
foreach ($smMailMessage->attachments as $k => $v) {
$message->attach(Swift_Attachment::fromPath($v));
}
$type = $message->getHeaders()->get('Content-Type');
$type->setValue('text/html');
$type->setParameter('charset', $this->charset);
$message->setBody($smMailMessage->HTMLBody)->addPart($smMailMessage->HtmlToTextBody());
$success = $this->mailer->send($message, $error) > 0;
return array('success' => $success, 'mailStream' => $success ? $message->toString() : null, 'error' => $error);
}
示例3: attach
protected function attach($attachment)
{
if (!$attachment instanceof Swift_Attachment) {
$attachment = Swift_Attachment::fromPath($attachment);
}
return $this->message->attach($attachment);
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
//generacion xlsx
$em = $this->getContainer()->get('doctrine')->getManager();
$emailDara = $em->getRepository('BackendBundle:EmailList')->findOneByName('Email Dara');
$researches = $em->getRepository('BackendBundle:Research')->programationUnsendedToDara();
$date = date("d-M-Y h:i:s");
if (count($researches) == 0) {
$output->writeln($date . ": No hay programaciones para este periodo");
} else {
try {
$this->generateProgramacionXLSX($researches);
} catch (Exception $e) {
$output->writeln($e->getMessage());
return $e->getMessage();
}
$output->writeln($date . ": Programacion generada");
//enviar por email
$today = date("d-M-Y");
$filename = "Programacion_" . $today;
$path = $this->getContainer()->get('kernel')->getRootDir() . "/../web/Programaciones/";
$message = \Swift_Message::newInstance()->setSubject('Programación de Cursos IPre')->setFrom('gestionIPre@ing.puc.cl')->setTo(array($emailDara->getEmail()))->setBody("Hola, adjuntamos la programación de cursos de este mes, saludos, \nGestión IPre")->attach(\Swift_Attachment::fromPath($path . $filename . ".xlsx"));
$this->getContainer()->get('mailer')->send($message);
$output->writeln($date . ": Programacion enviada");
// seteamos los estados como programacion envada a dara
foreach ($researches as $research) {
$research->getApplication()->setState(4);
$em->flush();
}
}
}
示例5: sendEmail
/**
* Send a email using t3lib_htmlmail or the new swift mailer
* It depends on the TYPO3 version
*/
public static function sendEmail($to, $subject, $message, $type = 'plain', $fromEmail = '', $fromName = '', $charset = 'utf-8', $files = array())
{
$mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
$mail->setTo(explode(',', $to));
$mail->setSubject($subject);
$mail->setCharset($charset);
$mail->setFrom(array($fromEmail => $fromName));
$mail->setReplyTo(array($fromEmail => $fromName));
// add Files
if (!empty($files)) {
foreach ($files as $file) {
$mail->attach(Swift_Attachment::fromPath($file));
}
}
// add Plain
if ($type == 'plain') {
$mail->addPart($message, 'text/plain');
}
// add HTML
if ($type == 'html') {
$mail->setBody($message, 'text/html');
}
// send
$mail->send();
}
示例6: onFormProcessed
/**
* Send email when processing the form data.
*
* @param Event $event
*/
public function onFormProcessed(Event $event)
{
$form = $event['form'];
$action = $event['action'];
$params = $event['params'];
if (!$this->email->enabled()) {
return;
}
switch ($action) {
case 'email':
// Prepare Twig variables
$vars = array('form' => $form);
// Build message
$message = $this->buildMessage($params, $vars);
if (isset($params['attachments'])) {
$filesToAttach = (array) $params['attachments'];
if ($filesToAttach) {
foreach ($filesToAttach as $fileToAttach) {
$filesValues = $form->value($fileToAttach);
if ($filesValues) {
foreach ($filesValues as $fileValues) {
$filename = $fileValues['file'];
$message->attach(\Swift_Attachment::fromPath($filename));
}
}
}
}
}
// Send e-mail
$this->email->send($message);
break;
}
}
示例7: send
public function send($lastOverride = false)
{
$i18n = Localization::getTranslator();
$lastFn = '/home/pi/phplog/last-tx-sent';
$last = 0;
if (file_exists($lastFn)) {
$last = intval(trim(file_get_contents($lastFn)));
}
if ($lastOverride !== false) {
$last = $lastOverride;
}
$csvMaker = Container::dispense('TransactionCSV');
$config = Admin::volatileLoad()->getConfig();
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername($config->getEmailUsername())->setPassword($config->getEmailPassword());
$msg = Swift_Message::newInstance()->setSubject($config->getMachineName() . $i18n->_(': Transaction Log'))->setFrom([$config->getEmailUsername() => $config->getMachineName()])->setTo(array($config->getEmailUsername()))->setBody($i18n->_('See attached for transaction log.'));
$file = $csvMaker->save($last);
if (!$file) {
throw new Exception('Unable to save CSV');
}
$msg->attach(Swift_Attachment::fromPath($file));
file_put_contents($lastFn, $csvMaker->getLastID());
$mailer = Swift_Mailer::newInstance($transport);
if (!$mailer->send($msg)) {
throw new Exception('Unable to send: unkown cause');
}
}
示例8: sendMail
public function sendMail()
{
$transport = Swift_SmtpTransport::newInstance($this->instance, $this->smtp_port);
$transport->setUsername($this->username);
$transport->setPassword($this->user_password);
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message->setFrom($this->setFrom);
$message->setTo($this->setTo);
$message->setSubject($this->subject);
$message->setBody($this->setBody, 'text/html', 'utf-8');
if (!empty($this->setfilepath)) {
$message->attach(Swift_Attachment::fromPath($this->setfilepath)->setFilename($this->aliasname));
}
/*try{
if($mailer->send($message)){
return true;
}
}
catch (Swift_ConnectionException $e){
//echo 'There was a problem communicating with SMTP: ' . $e->getMessage();
return false;
}*/
return $mailer->send($message);
}
示例9: send
static function send($title, $body, $to_array, $attachment = null, $log = true)
{
$model = Config::find()->one();
// Create the message
$message = \Swift_Message::newInstance()->setSubject($title)->setFrom(array($model->from_email => $model->from_name))->setTo($to_array)->setBody($body);
// Optionally add any attachments
if ($attachment) {
if (is_array($attachment)) {
foreach ($attachment as $file) {
$message = $message->attach(Swift_Attachment::fromPath($file));
}
} else {
$message = $message->attach(Swift_Attachment::fromPath($attachment));
}
}
// Create the Transport
switch ($model->type) {
case 1:
$transport = \Swift_SmtpTransport::newInstance($model->smtp, $model->port > 0 ?: 25)->setUsername($model->from_email)->setPassword($model->pass);
break;
case 2:
$transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
break;
case 3:
$transport = \Swift_MailTransport::newInstance();
break;
}
$mailer = \Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
//log send mail
if (true === $log) {
static::log($to_array, $title, $body, $attachment);
}
}
示例10: sendEmail
public static function sendEmail($receiver, $obj = "Aucun objet", $content = "", $urlFile = "", $nameFile = "")
{
global $config;
global $twig;
$message = Swift_Message::newInstance();
$template = $twig->loadTemplate("email_generique.html5.twig");
$view = $template->render(["objEmail" => $obj, "messageEmail" => $content]);
$arrMatches = array();
preg_match_all('/(src=|url\\()"([^"]+\\.(jpe?g|png|gif|bmp|tiff?|swf))"/Ui', $view, $arrMatches);
foreach (array_unique($arrMatches[2]) as $url) {
$src = rawurldecode($url);
// see #3713
if (!preg_match('@^https?://@', $src) && file_exists(BASE_ROOT . '/' . $src)) {
$cid = $message->embed(Swift_EmbeddedFile::fromPath(BASE_ROOT . '/' . $src));
$view = str_replace(array('src="' . $url . '"', 'url("' . $url . '"'), array('src="' . $cid . '"', 'url("' . $cid . '"'), $view);
}
}
$message->setSubject($obj);
$message->setFrom($config["smtp"]["sender"]);
$message->setReplyTo($config["smtp"]["replyTo"]);
$message->setTo($receiver);
$message->setBody($view, 'text/html');
if ($urlFile !== "") {
$message->attach(Swift_Attachment::fromPath($urlFile)->setFilename($nameFile));
}
$mailer = self::getMailer();
$mailer->send($message);
}
示例11: mailSender
/**
* Sends out an email to specified recipients using given message and other optional parameters.
* @param array $components Mixed value array containing components to create a message.
* @return integer number of recipients the message was sent to.
*/
function mailSender($components)
{
//Create transport
$transport = Swift_SmtpTransport::newInstance('insert mail/smtp server here', 25)->setUsername('insert username here')->setPassword('insert password here');
//Create mail using transport
$mailer = Swift_Mailer::newInstance($transport);
//Create message. Minimum required: from, to, subject, message.
$message = Swift_Message::newInstance();
$message->setSubject($components['subject'])->setFrom($components['from'])->setTo($components['to'])->setBody($components['body'], 'text/html');
//Optional parameters. Check to see if array contains additional parameters to add to the message.
if (array_key_exists('bcc', $components)) {
$message->setBcc($components['bcc']);
}
if (array_key_exists('cc', $components)) {
$message->setCc($components['cc']);
}
if (array_key_exists('attachment', $components)) {
if (is_array($components['attachment'])) {
foreach ($components['attachment'] as $attachment) {
$message->attach(Swift_Attachment::fromPath($attachment));
}
} else {
$message->attach(Swift_Attachment::fromPath($components['attachment']));
}
}
return $mailer->send($message);
}
示例12: testAttachmentSending
public function testAttachmentSending()
{
$mailer = $this->_getMailer();
$message = Swift_Message::newInstance('[Swift Mailer] HtmlWithAttachmentSmokeTest')->setFrom(array(SWIFT_SMOKE_EMAIL_ADDRESS => 'Swift Mailer'))->setTo(SWIFT_SMOKE_EMAIL_ADDRESS)->attach(Swift_Attachment::fromPath($this->_attFile))->setBody('<p>This HTML-formatted message should contain an attached ZIP file (named "textfile.zip").' . PHP_EOL . 'When unzipped, the archive should produce a text file which reads:</p>' . PHP_EOL . '<p><q>This is part of a Swift Mailer v4 smoke test.</q></p>', 'text/html');
$this->assertEqual(1, $mailer->send($message), '%s: The smoke test should send a single message');
$this->_visualCheck('http://swiftmailer.org/smoke/4.0.0/html_with_attachment.jpg');
}
示例13: testSend
public function testSend()
{
$message = new Swift_Message();
$message->setFrom('johnny5@example.com', 'Johnny #5');
$message->setSubject('Is alive!');
$message->addTo('you@example.com', 'A. Friend');
$message->addTo('you+two@example.com');
$message->addCc('another+1@example.com');
$message->addCc('another+2@example.com', 'Extra 2');
$message->addBcc('another+3@example.com');
$message->addBcc('another+4@example.com', 'Extra 4');
$message->addPart('<q>Help me Rhonda</q>', 'text/html');
$message->addPart('Doo-wah-ditty.', 'text/plain');
$attachment = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain');
$attachment2 = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain');
$attachment2->setDisposition('inline');
$message->attach($attachment);
$message->attach($attachment2);
$message->setPriority(1);
$headers = $message->getHeaders();
$headers->addTextHeader('X-PM-Tag', 'movie-quotes');
$messageId = $headers->get('Message-ID')->getId();
$transport = new PostmarkTransportStub('TESTING_SERVER');
$client = $this->getMock('GuzzleHttp\\Client', array('request'));
$transport->setHttpClient($client);
$o = PHP_OS;
$v = phpversion();
$client->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('https://api.postmarkapp.com/email'), $this->equalTo(['headers' => ['X-Postmark-Server-Token' => 'TESTING_SERVER', 'User-Agent' => "swiftmailer-postmark (PHP Version: {$v}, OS: {$o})", 'Content-Type' => 'application/json'], 'json' => ['From' => '"Johnny #5" <johnny5@example.com>', 'To' => '"A. Friend" <you@example.com>,you+two@example.com', 'Cc' => 'another+1@example.com,"Extra 2" <another+2@example.com>', 'Bcc' => 'another+3@example.com,"Extra 4" <another+4@example.com>', 'Subject' => 'Is alive!', 'Tag' => 'movie-quotes', 'TextBody' => 'Doo-wah-ditty.', 'HtmlBody' => '<q>Help me Rhonda</q>', 'Headers' => [['Name' => 'Message-ID', 'Value' => '<' . $messageId . '>'], ['Name' => 'X-PM-KeepID', 'Value' => 'true'], ['Name' => 'X-Priority', 'Value' => '1 (Highest)']], 'Attachments' => [['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt'], ['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt', 'ContentID' => 'cid:' . $attachment2->getId()]]]]));
$transport->send($message);
}
示例14: sendMessage
protected function sendMessage($templateName, $context, $fromEmail, $toEmail, array $attachments = array())
{
$template = $this->twig->loadTemplate($templateName);
$subject = $template->renderBlock('subject', $context);
$textBody = $template->renderBlock('body_text', $context);
$htmlBody = $template->renderBlock('body_html', $context);
$message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($fromEmail)->setTo($toEmail);
if (!empty($htmlBody)) {
$message->setBody($htmlBody, 'text/html')->addPart($textBody, 'text/plain');
} else {
$message->setBody($textBody);
}
if (is_array($attachments) && !empty($attachments)) {
foreach ($attachments as $filename => $path) {
//TODO need to assure to use correct absolute path!
if (file_exists($path)) {
$attachment = \Swift_Attachment::fromPath($path);
if (is_string($filename)) {
$attachment->setFilename($filename);
}
$message->attach($attachment);
}
}
}
$this->mailer->send($message);
}
示例15: to
public static function to($email, $subject, $content, $part, $attach)
{
$mailconfig = Config::get('mail');
$transport = \Swift_SmtpTransport::newInstance($mailconfig['host'], $mailconfig['port'])->setUsername($mailconfig['username'])->setPassword($mailconfig['password']);
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create the message
$message = \Swift_Message::newInstance($subject)->setFrom(array($mailconfig['from']['address'] => $mailconfig['from']['name']));
// Set the To addresses with an associative array
if (!is_array($email)) {
throw new \Exception("发送邮件必须是关联数组", 1);
}
$message->setTo($email);
// Give it a body
$message->setBody($content);
// And optionally an alternative body
if ($part) {
$message->addPart($part, 'text/html');
}
// Optionally add any attachments
if ($attach) {
$message->attach(Swift_Attachment::fromPath($attach));
}
// Send the message
if (!$mailer->send($message, $failures)) {
return $failures;
} else {
return true;
}
}