本文整理汇总了PHP中Swift_Attachment::fromPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Attachment::fromPath方法的具体用法?PHP Swift_Attachment::fromPath怎么用?PHP Swift_Attachment::fromPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Attachment
的用法示例。
在下文中一共展示了Swift_Attachment::fromPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: handle
/**
* Listen contact message request;
*/
private function handle(Request $request)
{
$email = $request->request->get('feedback_user_email');
$name = $request->request->get('feedback_user_name');
$email = $request->request->get('feedback_user_email');
$subject = $request->request->get('feedback_subject');
$message = $request->request->get('feedback_message');
$captcha = $request->request->get('g-recaptcha-response');
if (empty($email) || empty($message)) {
return;
}
if (!$this->captchaIsValid($captcha)) {
return;
}
$uploadedFile = $request->files->get('lampiran');
$attachedFile = false;
if ($uploadedFile) {
// NOTE: $attachedFile variable is used below for mail attachment
$attachedFile = $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getClientOriginalName();
$uploadedFileSize = $uploadedFile->getSize();
$uploadedFileSizeLimit = static::fileUploadMaxSize();
if ($uploadedFileSize > $uploadedFileSizeLimit) {
// @todo change this to template
echo '<script>alert("FILE TOO BIG");</script>';
echo '<script>setTimeout(function(){ window.location = window.location.href }, 2000);</script>';
exit;
}
$uploadedFile->move($uploadedFile->getPath(), $uploadedFile->getClientOriginalName());
}
try {
$messageBody = sprintf(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'mail_format.php'), $name, $email, $subject, $message);
$smtpUser = $this->getOption('smtp_user');
$smtpPass = $this->getOption('smtp_pass');
$smtpHost = $this->getOption('smtp_host');
$smtpPort = $this->getOption('smtp_port', 465);
$smtpSsl = $this->getOption('smtp_ssl', 0);
$mailFrom = $smtpUser;
$mailFromName = $this->getOption('mail_from_name');
$mailTos = $this->getMailTos();
$message = Swift_Message::newInstance()->setSubject($subject)->setFrom($mailFrom, $mailFromName)->setTo($mailTos)->setBody($messageBody);
if ($attachedFile) {
$message->attach(\Swift_Attachment::fromPath($attachedFile));
}
if ($smtpSsl) {
$transport = Swift_SmtpTransport::newInstance($smtpHost, $smtpPort, 'ssl');
} else {
$transport = Swift_SmtpTransport::newInstance($smtpHost, $smtpPort);
}
$transport->setUsername($smtpUser)->setPassword($smtpPass);
$mailer = Swift_Mailer::newInstance($transport);
// Send the message
$result = $mailer->send($message);
if ($result) {
header("Location: " . get_site_url(NULL, 'contact') . '?contact-message-sent=1');
exit;
}
} catch (\Exception $e) {
throw $e;
}
}
示例3: 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();
}
}
}
示例4: _mapToSwift
protected function _mapToSwift(SendGrid\Email $mail)
{
$message = new \Swift_Message($mail->getSubject());
/*
* Since we're sending transactional email, we want the message to go to one person at a time, rather
* than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers
* but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be
* ignored anyway.
*/
$message->setTo($mail->to);
$message->setFrom($mail->getFrom(true));
$message->setCc($mail->getCcs());
$message->setBcc($mail->getBccs());
if ($mail->getHtml()) {
$message->setBody($mail->getHtml(), 'text/html');
if ($mail->getText()) {
$message->addPart($mail->getText(), 'text/plain');
}
} else {
$message->setBody($mail->getText(), 'text/plain');
}
if ($replyto = $mail->getReplyTo()) {
$message->setReplyTo($replyto);
}
$attachments = $mail->getAttachments();
//add any attachments that were added
if ($attachments) {
foreach ($attachments as $attachment) {
$message->attach(\Swift_Attachment::fromPath($attachment['file']));
}
}
$message_headers = $message->getHeaders();
$message_headers->addTextHeader("x-smtpapi", $mail->smtpapi->jsonString());
return $message;
}
示例5: _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);
}
示例6: 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);
}
示例7: 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);
}
}
示例8: 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');
}
}
示例9: testAttachmentSending
public function testAttachmentSending()
{
$mailer = $this->_getMailer();
$message = Swift_Message::newInstance()->setCharset('utf-8')->setSubject('[Swift Mailer] InternationalSmokeTest (διεθνής)')->setFrom(array(SWIFT_SMOKE_EMAIL_ADDRESS => 'Χριστοφορου (Swift Mailer)'))->setTo(SWIFT_SMOKE_EMAIL_ADDRESS)->setBody('This message should contain an attached ZIP file (named "κείμενο, εδάφιο, θέμα.zip").' . PHP_EOL . 'When unzipped, the archive should produce a text file which reads:' . PHP_EOL . '"This is part of a Swift Mailer v4 smoke test."' . PHP_EOL . PHP_EOL . 'Following is some arbitrary Greek text:' . PHP_EOL . 'Δεν βρέθηκαν λέξεις.')->attach(Swift_Attachment::fromPath($this->_attFile)->setContentType('application/zip')->setFilename('κείμενο, εδάφιο, θέμα.zip'));
$this->assertEqual(1, $mailer->send($message), '%s: The smoke test should send a single message');
$this->_visualCheck('http://swiftmailer.org/smoke/4.0.0/international.jpg');
}
示例10: 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');
}
示例11: 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;
}
}
示例12: attach
protected function attach($attachment)
{
if (!$attachment instanceof Swift_Attachment) {
$attachment = Swift_Attachment::fromPath($attachment);
}
return $this->message->attach($attachment);
}
示例13: mail
public function mail(CategoryEvent $event)
{
/** @var BaseHandler $handler */
$handler = $event->getParam('handler');
if ($handler) {
$dateFormat = 'Y-m-d h:i:s';
$mailer = new Mailer();
$mailer->setGroup('product');
$message = $mailer->getMessage();
$message->setSubject($handler->getUrl() . ' ' . date($dateFormat));
$body = 'Script started at: ' . date($dateFormat, $this->registry->startTime) . PHP_EOL;
$body .= 'Script finished at: ' . date($dateFormat) . '; Total execute time: ' . date('i:s', time() - $this->registry->startTime) . PHP_EOL;
$body .= 'Parsed urls: ' . $handler->getJobTotal() . PHP_EOL;
$message->setBody($body);
$fileParts = pathinfo($this->config->getParseDir() . $handler->getFileName());
$fname = $this->config->getParseDir() . $handler->getFileName();
file_exists($fname) ? $message->attach(\Swift_Attachment::fromPath($fname)) : null;
$fname = $this->config->getParseDir() . $fileParts['filename'] . '_disappeared_products.' . $fileParts['extension'];
file_exists($fname) ? $message->attach(\Swift_Attachment::fromPath($fname)) : null;
$fname = $this->config->getParseDir() . $fileParts['filename'] . '_newProducts.' . $fileParts['extension'];
file_exists($fname) ? $message->attach(\Swift_Attachment::fromPath($fname)) : null;
$fname = $this->config->getParseDir() . $fileParts['filename'] . '_recently_reviewed_products.' . $fileParts['extension'];
file_exists($fname) ? $message->attach(\Swift_Attachment::fromPath($fname)) : null;
$mailer->send();
}
}
示例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: sendEmail
public function sendEmail($to, $cc, $bcc, $replay, $body, $nombreArchivos, $asunto)
{
$email = \Swift_Message::newInstance();
$email->setContentType('text/html');
$email->setFrom($this->from, 'La Plus Belle y Sonodigest');
$email->setTo($to);
foreach ($nombreArchivos as $key => $nombre) {
$email->attach(\Swift_Attachment::fromPath('http://190.53.176.116/laplusbelle/Photos/correos/' . $nombre));
}
if ($cc != null) {
$email->setCc($cc);
}
if ($replay != null) {
$email->setReplyTo($replay);
} else {
$email->setReplyTo('no-reply@laplusbelle.com.sv');
}
if ($bcc != null) {
$email->setBcc($bcc);
}
//$email->setSubject($this->subject);
$email->setSubject($asunto);
$email->setBody($body);
$this->mail->send($email);
}