本文整理汇总了PHP中Swift_Message::attach方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::attach方法的具体用法?PHP Swift_Message::attach怎么用?PHP Swift_Message::attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::attach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: send
/**
* Sends the digest
*/
public function send()
{
$lastMonths = new \DateTime();
$lastMonths->modify('-6 month');
$parameters = array('modified_at >= ?0 AND digest = "Y" AND notifications <> "N"', 'bind' => array($lastMonths->getTimestamp()));
$users = array();
foreach (Users::find($parameters) as $user) {
if ($user->email && strpos($user->email, '@') !== false && strpos($user->email, '@users.noreply.github.com') === false) {
$users[trim($user->email)] = $user->name;
}
}
$fromName = $this->config->mail->fromName;
$fromEmail = $this->config->mail->fromEmail;
$url = $this->config->site->url;
$subject = 'Top Stories from Phosphorum ' . date('d/m/y');
$lastWeek = new \DateTime();
$lastWeek->modify('-1 week');
$order = 'number_views + ' . '((IF(votes_up IS NOT NULL, votes_up, 0) - ' . 'IF(votes_down IS NOT NULL, votes_down, 0)) * 4) + ' . 'number_replies + IF(accepted_answer = "Y", 10, 0) DESC';
$parameters = array('created_at >= ?0 AND deleted != 1 AND categories_id <> 4', 'bind' => array($lastWeek->getTimestamp()), 'order' => $order, 'limit' => 10);
$e = $this->escaper;
$content = '<html><head></head><body><p><h1 style="font-size:22px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;padding:16px 0;border-bottom:1px solid #e2e2e2">Top Stories from Phosphorum</h1></p>';
foreach (Posts::find($parameters) as $post) {
$user = $post->user;
if ($user == false) {
continue;
}
$content .= '<p><a style="text-decoration:none;display:block;font-size:20px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">' . $e->escapeHtml($post->title) . '</a></p>';
$content .= '<p><table width="100%"><td><table><tr><td>' . '<img src="https://secure.gravatar.com/avatar/' . $user->gravatar_id . '?s=32&r=pg&d=identicon" width="32" height="32" alt="' . $user->name . ' icon">' . '</td><td><a style="text-decoration:none;color:#155fad" href="' . $url . '/user/' . $user->id . '/' . $user->login . '">' . $user->name . '<br><span style="text-decoration:none;color:#999;text-decoration:none">' . $user->getHumanKarma() . '</span></a></td></tr></table></td><td align="right"><table style="border: 1px solid #dadada;" cellspacing=5>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Created</label><br>' . $post->getHumanCreatedAt() . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Replies</label><br>' . $post->number_replies . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Views</label><br>' . $post->number_views . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Votes</label><br>' . ($post->votes_up - $post->votes_down) . '</td>' . '</tr></table></td></tr></table></p>';
$content .= $this->markdown->render($e->escapeHtml($post->content));
$content .= '<p><a style="color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">Read more</a></p>';
$content .= '<hr style="border: 1px solid #dadada">';
}
$textContent = strip_tags($content);
$htmlContent = $content . '<p style="font-size:small;-webkit-text-size-adjust:none;color:#717171;">';
$htmlContent .= PHP_EOL . 'This email was sent by Phalcon Framework. Change your e-mail preferences <a href="' . $url . '/settings">here</a></p>';
foreach ($users as $email => $name) {
try {
$message = new \Swift_Message('[Phalcon Forum] ' . $subject);
$message->setTo(array($email => $name));
$message->setFrom(array($fromEmail => $fromName));
$bodyMessage = new \Swift_MimePart($htmlContent, 'text/html');
$bodyMessage->setCharset('UTF-8');
$message->attach($bodyMessage);
$bodyMessage = new \Swift_MimePart($textContent, 'text/plain');
$bodyMessage->setCharset('UTF-8');
$message->attach($bodyMessage);
if (!$this->transport) {
$this->transport = \Swift_SmtpTransport::newInstance($this->config->smtp->host, $this->config->smtp->port, $this->config->smtp->security);
$this->transport->setUsername($this->config->smtp->username);
$this->transport->setPassword($this->config->smtp->password);
}
if (!$this->mailer) {
$this->mailer = \Swift_Mailer::newInstance($this->transport);
}
$this->mailer->send($message);
} catch (\Exception $e) {
echo $e->getMessage(), PHP_EOL;
}
}
}
示例3: executePassword
public function executePassword()
{
$this->form = new RequestPasswordForm();
if ($this->getRequest()->isMethod('get')) {
return;
}
$this->form->bind($this->getRequest()->getParameter('form'));
if (!$this->form->isValid()) {
return;
}
$email = $this->form->getValue('email');
$password = substr(md5(rand(100000, 999999)), 0, 6);
$sfGuardUserProfile = sfGuardUserProfilePeer::retrieveByEmail($email);
$sfGuardUser = $sfGuardUserProfile->getSfGuardUser();
$sfGuardUser->setPassword($password);
try {
$connection = new Swift_Connection_SMTP('mail.sis-nav.com', 25);
$connection->setUsername('umut.utkan@sistemas.com.tr');
$connection->setPassword('gahve123');
$mailer = new Swift($connection);
$message = new Swift_Message('Request Password');
$mailContext = array('email' => $email, 'password' => $password, 'username' => $sfGuardUser->getUsername(), 'full_name' => $sfGuardUserProfile->getFirstName());
$message->attach(new Swift_Message_Part($this->getPartial('mail/requestPasswordHtmlBody', $mailContext), 'text/html'));
$message->attach(new Swift_Message_Part($this->getPartial('mail/requestPasswordTextBody', $mailContext), 'text/plain'));
$mailer->send($message, $email, 'admin@project-y.com');
$mailer->disconnect();
} catch (Exception $e) {
$mailer->disconnect();
}
$sfGuardUser->save();
$this->getUser()->setFlash('info', 'A new password is sent to your email.');
$this->forward('site', 'message');
}
示例4: execute
protected function execute($arguments = array(), $options = array())
{
// initialize the database connection
$databaseManager = new sfDatabaseManager($this->configuration);
$connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
// add your code here
$blogs = Doctrine::getTable('Blog');
$blogs_to_process = $blogs->findByIsThumbnail(0);
foreach ($blogs_to_process as $blog) {
$thumbalizr_url = 'http://api.thumbalizr.com?';
$params = array('url' => $blog->url, 'width' => 300);
$api_url = $thumbalizr_url . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
$res_tab = http_parse_headers($res);
if (!empty($res_tab['X-Thumbalizr-Status']) && $res_tab['X-Thumbalizr-Status'] == 'OK') {
// Image is ready let's store the URL!
$image_data = file_get_contents($api_url);
$path = sfConfig::get('app_image_path');
$url = sfConfig::get('app_image_url');
$image_name = md5($blog->url);
echo $path . $image_name . "\n";
file_put_contents($path . $image_name . '.jpg', $image_data);
$blog->thumbnail_url = $image_name . '.jpg';
$blog->is_thumbnail = 1;
$blog->save();
// Send mail to notify the blo will get into the game!
try {
// Create the mailer and message objects
//$mailer = new Swift(new Swift_Connection_NativeMail());
//$connection = new Swift_Connection_SMTP('smtp.free.fr');
$connection = new Swift_Connection_NativeMail();
$mailer = new Swift($connection);
$message = new Swift_Message('Welcome!');
// Render message parts
$mailContext = array('admin_hash' => $blog->getAdmin_hash(), 'blog_url' => $blog->getUrl());
$v = $this->getPartial('newBlogMailHtmlBody', $mailContext);
$htmlPart = new Swift_Message_Part($v, 'text/html');
$message->attach($htmlPart);
$message->attach(new Swift_Message_Part($this->getPartial('newBlogMailTextBody', $mailContext), 'text/plain'));
$mailTo = $blog->getEmail();
$mailFrom = sfConfig::get('app_mail_webmaster');
$mailer->send($message, $mailTo, $mailFrom);
$mailer->disconnect();
} catch (Exception $e) {
$this->logMessage($e);
}
} else {
//print_r($res_tab);
}
}
}
示例5: prepare
/**
* {@inheritdoc}
*/
public function prepare($from, $fromName, array $to, $subject, $body, array $attachments = array(), array $options = array())
{
$this->mail = \Swift_Message::newInstance()->setSubject($subject)->setFrom($from)->setBody($body, 'text/html');
foreach ($to as $receiver) {
$this->mail->addTo($receiver);
}
if (!empty($attachments)) {
foreach ($attachments as $attachment) {
$this->mail->attach(\Swift_Attachment::fromPath($attachment));
}
}
}
示例6: send_mail
/**
* 邮件发送
* @return boolean
*/
public function send_mail($recipient, $mailsubject, $mailbody)
{
apf_require_file("Swift.php");
Swift_ClassLoader::load("Swift_Connection_SMTP");
$message = new Swift_Message($mailsubject);
$message->setFrom("安居客<noreply@dm.anjuke.com>");
$message->attach(new Swift_Message_Part(strip_tags($mailbody), "text/plain", "base64", "utf-8"));
$message->attach(new Swift_Message_Part($mailbody, "text/html", "base64", "utf-8"));
foreach ($recipient as $re) {
Mail_Queue::put('noreply@dm.anjuke.com', $re, $mailsubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
}
return true;
}
示例7: send_mail
/**
* 邮件发送
* @param recipient 邮件接收方email
* @param mailsubject 邮件主题
* @param mailbody 邮件内容
* @return boolean
*/
private function send_mail($recipient, $mailsubject, $mailbody)
{
try {
$message = new Swift_Message($mailsubject);
$message->setFrom("安居客<" . $this->sender . ">");
$message->setTo($recipient);
$message->attach(new Swift_Message_Part(strip_tags($mailbody), "text/plain", "base64", "utf-8"));
$message->attach(new Swift_Message_Part($mailbody, "text/html", "base64", "utf-8"));
Mail_Queue::put($this->sender, $recipient, $mailsubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
return true;
} catch (Exception $e) {
return false;
}
}
示例8: _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;
}
示例9: send
/**
* {@inheritdoc}
*/
public function send($from, $to, $subject, $body, $replyTo = null, $attachments = [])
{
$message = new \Swift_Message($subject, $body);
// set from and to
$message->setFrom($from);
$message->setTo($to);
// set attachments
if (count($attachments) > 0) {
foreach ($attachments as $file) {
if ($file instanceof \SplFileInfo) {
$path = $file->getPathName();
$name = $file->getFileName();
// if uploadedfile get original name
if ($file instanceof UploadedFile) {
$name = $file->getClientOriginalName();
}
$message->attach(\Swift_Attachment::fromPath($path)->setFilename($name));
}
}
}
// set replyTo
if ($replyTo != null) {
$message->setReplyTo($replyTo);
}
return $this->mailer->send($message);
}
示例10: testBodySwap
public function testBodySwap()
{
$message1 = new Swift_Message('Test');
$html = Swift_MimePart::newInstance('<html></html>', 'text/html');
$html->getHeaders()->addTextHeader('X-Test-Remove', 'Test-Value');
$html->getHeaders()->addTextHeader('X-Test-Alter', 'Test-Value');
$message1->attach($html);
$source = $message1->toString();
$message2 = clone $message1;
$message2->setSubject('Message2');
foreach ($message2->getChildren() as $child) {
$child->setBody('Test');
$child->getHeaders()->removeAll('X-Test-Remove');
$child->getHeaders()->get('X-Test-Alter')->setValue('Altered');
}
$final = $message1->toString();
if ($source != $final) {
$this->fail("Difference although object cloned \n [" . $source . "]\n[" . $final . "]\n");
}
$final = $message2->toString();
if ($final == $source) {
$this->fail('Two body matches although they should differ' . "\n [" . $source . "]\n[" . $final . "]\n");
}
$id_1 = $message1->getId();
$id_2 = $message2->getId();
$this->assertEquals($id_1, $id_2, 'Message Ids differ');
$id_2 = $message2->generateId();
$this->assertNotEquals($id_1, $id_2, 'Message Ids are the same');
}
示例11: embedFile
/**
* Embed an inline file into the message, such as a Image or MIDI file
* @param mixed The file contents, Swift_File object or Swift_Message_EmbeddedFile object
* @param string The content-type of the file, optional
* @param string The filename to use, optional
* @param string the Content-ID to use, optional
* @return string
*/
public function embedFile($data, $type = "application/octet-stream", $filename = null, $cid = null)
{
$ret = false;
if ($data instanceof Swift_Message_EmbeddedFile) {
$ret = $this->message->attach($data);
$this->attachmentIds[] = $ret;
return $ret;
} elseif ($data instanceof Swift_File) {
try {
$ret = $this->message->attach(new Swift_Message_EmbeddedFile($data, $filename, $type, $cid));
$this->attachmentIds[] = $ret;
return $ret;
} catch (Swift_Message_MimeException $e) {
$this->setError("An attachment failed to attach:<br />" . $e->getMessage());
return false;
} catch (Swift_FileException $e) {
$this->setError("An attachment failed to attach:<br />" . $e->getMessage());
return false;
}
} else {
try {
$ret = $this->message->attach(new Swift_Message_EmbeddedFile($data, $filename, $type, $cid));
$this->attachmentIds[] = $ret;
return $ret;
} catch (Swift_Message_MimeException $e) {
$this->setError("An attachment failed to attach:<br />" . $e->getMessage());
return false;
} catch (Swift_FileException $e) {
$this->setError("An attachment failed to attach:<br />" . $e->getMessage());
return false;
}
}
}
示例12: _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);
}
示例13: testNonEmptyFileNameAsAttachement
public function testNonEmptyFileNameAsAttachement()
{
$message = new Swift_Message();
try {
$message->attach(Swift_Attachment::fromPath(__FILE__));
} catch (Exception $e) {
$this->fail('Path should not be empty');
}
}
示例14: go
public function go()
{
try {
$swift = new Swift($this->getConnection(), null, Swift::ENABLE_LOGGING);
$this->setSwiftInstance($swift);
$message = new Swift_Message("Smoke Test 2 - Multipart");
$message->attach(new Swift_Message_Part("This message was sent in plain text"));
$message->attach(new Swift_Message_Part("This message was sent in <strong>HTML</strong>", "text/html"));
$to = new Swift_Address(TestConfiguration::TO_ADDRESS, TestConfiguration::TO_NAME);
$from = new Swift_Address(TestConfiguration::FROM_ADDRESS, TestConfiguration::FROM_NAME);
$swift->send($message, $to, $from);
$this->to = $to->build();
$this->from = $from->build();
} catch (Exception $e) {
$this->failed = true;
$this->setError($e->getMessage());
}
$this->render();
}
示例15: sentMail
protected function sentMail($mailSubject, $mailBody)
{
if ($this->mailSwitch == true && !empty($this->mailAddress)) {
$mailto = $this->mailAddress;
apf_require_file("Swift.php");
Swift_ClassLoader::load("Swift_Connection_SMTP");
$smtpuser = APF::get_instance()->get_config("SmtpUser");
$smtpemailto = $mailto;
$message = new Swift_Message($mailSubject);
$message->setFrom("安居客<" . $smtpuser . ">");
$message->setTo($smtpemailto);
$message->attach(new Swift_Message_Part(strip_tags($mailBody), "text/plain", "base64", "utf-8"));
$message->attach(new Swift_Message_Part($mailBody, "text/html", "base64", "utf-8"));
foreach ($smtpemailto as $to) {
if (!empty($to)) {
@Mail_Queue::put($smtpuser, $to, $mailSubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
}
}
}
}