本文整理匯總了PHP中Swift_Message::newInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Swift_Message::newInstance方法的具體用法?PHP Swift_Message::newInstance怎麽用?PHP Swift_Message::newInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::newInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sendMail
public function sendMail($parameters = array())
{
$em = $this->container->get('doctrine')->getManager();
$mailer = $this->container->get('mailer');
$body = $this->container->get('templating');
$baseUrl = $this->container->get('router')->getContext()->getHost();
if ($this->mailSubject === NULL || $this->mailSubject === '') {
throw new MissingOptionsException('El parámetro mailSubject (asunto del correo) no ha sido definido. mailSubject: ' . $this->mailSubject);
}
if ($this->mailFrom === NULL || $this->mailFrom === '') {
$this->mailFrom = $this->container->getParameter('mailer_email');
if ($this->mailFrom === NULL || $this->mailFrom === '') {
throw new ParameterNotFoundException('mail.service', 'mailer_email');
}
}
if ($this->mailTo === NULL || $this->mailTo === '') {
throw new MissingOptionsException('El parámetro mailTo (correo destinatario) no ha sido definido: ' . $this->mailTo);
}
$parameters['baseurl'] = $baseUrl;
$this->mailTemplate = $this->mailTemplate ? $this->mailTemplate : 'ApplicationCoreBundle:Mail:standardEmailLayout.html.twig';
$message = \Swift_Message::newInstance()->setSubject($this->mailSubject)->setFrom($this->mailFrom)->setTo($this->mailTo)->setBody($body->render($this->mailTemplate, $parameters), 'text/html');
$result = $mailer->send($message);
if ($result == 0) {
return false;
} else {
return true;
}
}
示例2: sendEmail
public function sendEmail() {
$this->emailConfig = $this->getEmailConfiguration();
$this->setMailer();
$mailerObject = Swift_Mailer::newInstance($this->transport);
#$mailerObject = sfContext::getInstance()->getMailer();
$message = Swift_Message::newInstance()
->setFrom($this->sender)
->setTo($this->receiver)
->setSubject($this->subject)
->setContentType($this->contentType)
->setBody($this->body);
if(isset($this->attachments)) {
foreach($this->attachments as $file) {
$fileObj = new File();
$filecontent = $fileObj->getFileContent($file['filepath']);
$message->attach(Swift_Attachment::newInstance($filecontent, $file['filename']));
}
}
try {
if($this->emailConfig['allowemailtransport'] == 1) {
$mailerObject->send($message);
}
}
catch (Exception $e) {
}
}
示例3: send
public static function send()
{
$transport = \Swift_SmtpTransport::newInstance('smtp.mail.ru', 465, 'ssl')->setUsername('ist70@mail.ru')->setPassword('');
$mailer = \Swift_Mailer::newInstance($transport);
$messages = \Swift_Message::newInstance('Wonderful Subject')->setFrom('my@example.com')->setTo(['eva@prokma.ru' => 'Работа'])->setContentType("text/html; charset=UTF-8")->setBody('Тестовое сообщение о БД', 'text/html');
$result = $mailer->send($messages);
}
示例4: __construct
/**
* Class constructor.
* Load all data from configurations and generate the initial clases
* to manage the email
*
* @param string Content type for message body. It usually text/plain or text/html.
* Default is 'text/plain' but can be changed later
*/
public function __construct($content_type = 'text/plain')
{
$config = RMFunctions::configs();
$config_handler =& xoops_gethandler('config');
$xconfig = $config_handler->getConfigsByCat(XOOPS_CONF_MAILER);
// Instantiate the Swit Transport according to our preferences
// We can change this preferences later
switch ($config['transport']) {
case 'mail':
$this->swTransport = Swift_MailTransport::newInstance();
break;
case 'smtp':
$this->swTransport = Swift_SmtpTransport::newInstance($config['smtp_server'], $config['smtp_port'], $config['smtp_crypt'] != 'none' ? $config['smtp_crypt'] : '');
$this->swTransport->setUsername($config['smtp_user']);
$this->swTransport->setPassword($config['smtp_pass']);
break;
case 'sendmail':
$this->swTransport = Swift_SendmailTransport::newInstance($config['sendmail_path']);
break;
}
// Create the message object
// Also this object could be change later with message() method
$this->swMessage = Swift_Message::newInstance();
$this->swMessage->setReplyTo($xconfig['from']);
$this->swMessage->setFrom(array($xconfig['from'] => $xconfig['fromname']));
$this->swMessage->setContentType($content_type);
}
示例5: __construct
function __construct()
{
// include swift mailer
require ENGINE_PATH . 'swiftmailer/classes/Swift.php';
Swift::init();
Swift::registerAutoload();
//Yii::import('system.vendors.swiftMailer.classes.Swift', true);
//Yii::registerAutoloader(array('Swift','autoload'));
require_once ENGINE_PATH . 'swiftmailer/swift_init.php';
//Yii::import('system.vendors.swiftMailer.swift_init', true);
switch ($this->params['transportType']) {
case 'smtp':
$transport = Swift_SmtpTransport::newInstance($this->params['smtpServer'], $this->params['smtpPort'], $this->params['smtpSequre'])->setUsername($this->params['smtpUsername'])->setPassword($this->params['smtpPassword']);
break;
case 'sendmail':
$transport = Swift_SendmailTransport::newInstance($this->params['sendmailCommand']);
break;
default:
case 'mail':
$transport = Swift_MailTransport::newInstance();
break;
}
$this->toEmail = 'noreplay@' . $_SERVER['HTTP_HOST'];
$this->fromEmail = 'noreplay@' . $_SERVER['HTTP_HOST'];
$this->path = "http://" . $_SERVER['HTTP_HOST'] . "/submit/mailtpl/";
$this->mailer = Swift_Mailer::newInstance($transport);
$this->mes = Swift_Message::newInstance();
}
示例6: onAuthenticationFailure
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
if ($request->request->has('_username')) {
$username = $request->request->get('_username');
} else {
$username = '';
}
//if ($exception->getMessage() === 'Captcha is invalid') {
//} else {
$failedLoginIp = $request->getClientIp();
$user = $this->fosUM->findUserByUsername($username);
if ($user) {
$failedLogin = $user->getFailedLogin();
$failedLogin++;
$user->setFailedLogin($failedLogin);
$user->setFailedLoginIp($failedLoginIp);
if ($failedLogin === 3) {
//email do użytkownika i admina
$message = \Swift_Message::newInstance()->setSubject('Nieautoryzowane próby dostępu do konta')->setFrom('noreply@bms.klimbest.pl')->setTo(array('pawel.zajder@klimbest.pl', $user->getEmail()))->setBody($username . ' próbował zalogować się zbyt wiele razy z adresu IP: ' . $failedLoginIp . ' ' . $exception->getMessage());
$this->mailer->send($message);
}
if ($failedLogin === 5) {
$user->setLocked(1);
}
$this->fosUM->updateUser($user);
}
//}
$url = 'fos_user_security_login';
$response = new RedirectResponse($this->router->generate($url));
return $response;
}
示例7: register
/**
* {@inheritdoc}
*/
public function register(Application $app)
{
$app['email.support'] = 'noreply@silex.nothing';
$app['logger.message_generator'] = function () use($app) {
$message = \Swift_Message::newInstance();
$message->setSubject('Error report from ' . $_SERVER['HTTP_HOST'])->setFrom($app['email.support'])->setTo($app['email.support']);
return $message;
};
$app['logger.swift_mailer_handler'] = $app->share(function ($app) {
$handler = new SwiftMailerHandler($app['mailer'], $app['logger.message_generator'], Logger::DEBUG);
$handler->setTransport($app['swiftmailer.transport']);
return $handler;
});
if (!$app['debug']) {
if ($this->send_emails) {
$app['monolog'] = $app->share($app->extend('monolog', function ($monolog, $app) {
/** @var $monolog Logger */
$bufferHander = new BufferHandler($app['logger.swift_mailer_handler']);
$fingersCrossedHandler = new FingersCrossedHandler($bufferHander, Logger::ERROR, 200);
$monolog->pushHandler($fingersCrossedHandler);
return $monolog;
}));
}
}
}
示例8: sendEmail
/**
* Send email using swift api.
*
* @param $body
* @param $recipients
* @param $from
* @param $subject
*/
public function sendEmail($body, $recipients, $from, $subject)
{
$config = Zend_Registry::get('config');
$failures = '';
Swift_Preferences::getInstance()->setCharset('UTF-8');
//Create the Transport
$transport = Swift_SmtpTransport::newInstance($config->mail->server->name, $config->mail->server->port, $config->mail->server->security)->setUsername($config->mail->username)->setPassword($config->mail->password);
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$headers = $message->getHeaders();
$headers->addTextHeader("signed-by", Constant::EMAIL_DOMAIN);
//Give the message a subject
$message->setSubject($subject);
//Set the From address with an associative array
$message->setFrom($from);
//Set the To addresses with an associative array
$message->setTo($recipients);
//Give it a body
$message->setBody($body);
$message->setContentType("text/html");
//Send the message
$myresult = $mailer->batchSend($message);
if ($myresult) {
return null;
} else {
return Constant::EMAIL_FAIL_MESSAGE;
}
}
示例9: send
/**
* Sends a message via email created by information given in the event.
*
* @param Event $event
*/
public function send(Event $event)
{
$subject = $this->varContainer->replace($this->subject);
$body = $this->container->get('templating')->render('KoalamonNotificationBundle:Sender:EMail/email_' . $event->getStatus() . '.html.twig', $this->varContainer->getTemplateVariables());
$message = \Swift_Message::newInstance()->setSubject($subject)->setFrom(['alert@koalamon.com' => 'KoalaAlert'])->setTo($this->emailAddresses)->setBody($body, 'text/html');
$this->container->get('mailer')->send($message);
}
示例10: swiftMessageInitializeAndSend
/**
* Prepares the (swift) email and sends it.
*
* @return int
*
* @throws \Exception If subject or recpient (to) not specified
*/
public function swiftMessageInitializeAndSend(array $data = array())
{
$swiftMessageInstance = \Swift_Message::newInstance();
if (!isset($data['subject'])) {
throw new \Exception('You need to specify a subject');
}
if (!isset($data['to'])) {
throw new \Exception('You need to specify a recipient');
}
$from = isset($data['from']) ? $data['from'] : $this->app['email'];
$to = $data['to'];
$swiftMessageInstance->setSubject($data['subject'])->setTo($to)->setFrom($from);
if (isset($data['cc'])) {
$swiftMessageInstance->setCc($data['cc']);
}
if (isset($data['bcc'])) {
$swiftMessageInstance->setBcc($data['bcc']);
}
$templateData = array('app' => $this->app, 'user' => $this->app['user'], 'email' => $to, 'swiftMessage' => $swiftMessageInstance);
if (isset($data['templateData'])) {
$templateData = array_merge($templateData, $data['templateData']);
}
if (isset($data['body'])) {
$bodyType = isset($data['bodyType']) ? $data['bodyType'] : 'text/html';
$isTwigTemplate = isset($data['contentIsTwigTemplate']) ? $data['contentIsTwigTemplate'] : true;
$swiftMessageBody = $this->app['mailer.css_to_inline_styles_converter']($data['body'], $templateData, $isTwigTemplate);
$swiftMessageInstance->setBody($swiftMessageBody, $bodyType);
}
return $this->app['mailer']->send($swiftMessageInstance);
}
示例11: postFlush
/**
*
* @param \Doctrine\ORM\Event\PostFlushEventArgs $args
*/
public function postFlush(Event\PostFlushEventArgs $args)
{
foreach ($this->inserted_entities as $entity) {
if ($entity instanceof Post && $entity->getId() > 0) {
$email = $entity->getTemplate()->getPostNotify();
if ($email) {
if (!$this->servicesLoaded) {
$this->loadServices();
}
$post = [];
foreach ($entity->getValueSet()->getValues() as $value) {
$post[$value->getAttribute()->getDisplayName()] = [];
if ($value instanceof OptionValue) {
$post_value = [];
foreach ($value->getOptions() as $option) {
$post_value[] = $option->getDisplayName();
}
} elseif ($value instanceof DateTimeValue) {
$post_value = [date("m/d/Y", $value->getValue()->getTimestamp())];
} else {
$post_value = [$value->getValue()];
}
$post[$value->getAttribute()->getDisplayName()] = $post_value;
}
$txt_template = "OpiferCmsBundle:Email:post-notify.txt.twig";
$txt_body = $this->twig->render($txt_template, ['post' => $post]);
$message = \Swift_Message::newInstance()->setSender($this->admin_email)->setFrom($this->admin_email)->setTo($email)->setBody($txt_body);
$this->sendEmail($message);
}
}
}
}
示例12: createAction
public function createAction(request $request)
{
$em = $this->getDoctrine()->getManager();
//getting the content
$content = $request->get('content');
//getting the user
$user = $this->container->get('security.context')->getToken()->getUser();
//getting the video
$video = $em->getRepository('BFSiteBundle:Video')->find($request->get('videoId'));
$comment = new Comment();
$comment->setContent($content)->setVideo($video)->setDate(new \Datetime())->setUser($user);
//we create a notification for the user of the video.
$message = $user->getUsername() . ' a laissé un commentaire sur la vidéo: ' . $video->getTitle() . '.';
$link = $this->generateUrl('bf_site_video', array('code' => $video->getCode()));
$service = $this->container->get('bf_site.notification');
$notification = $service->create($video->getUser(), $message, null, $link);
$em->persist($comment);
$em->persist($notification);
$em->flush();
if ($video->getUser()->getMailComment() === true) {
$message = \Swift_Message::newInstance()->setSubject($user->getUsername() . ' posted a new comment on your ' . $video->getTitle() . ' video')->setFrom('bestfootball@bestfootball.fr')->setTo($video->getUser()->getEmail())->setBody($this->renderView('Emails/comment.html.twig', array('user' => $video->getUser(), 'commenter' => $user, 'video' => $video)), 'text/html');
$this->get('mailer')->send($message);
}
$this->addFlash('success', 'Your comment has been added.');
return new response();
}
示例13: send
function send($view = 'default', $subject = '') {
// Create the message, and set the message subject.
$message = & Swift_Message::newInstance();
$message->setSubject($subject);
// Append the HTML and plain text bodies.
$bodyHTML = $this->_getBodyHTML($view);
$bodyText = $this->_getBodyText($view);
$message->setBody($bodyText, "text/plain");
$message->addPart($bodyHTML, "text/html");
// Set the from address/name.
$message->setFrom(array($this->from => $this->fromName));
// Create the recipient list.
//$recipients =& new Swift_RecipientList();
$message->setTo(array($this->to => $this->toName));
$transport->setHost('smtp.googlemail.com');
$transport->setPort(465);
$transport->setEncryption('tls');
$transport->setUsername('test.whatafind@gmail.com');
$transport->setPassword('whatafind6186');
$mailer = Swift_Mailer::newInstance($transport);
// Attempt to send the email.
$result = $mailer->send($message);
return $result;
}
示例14: inscriptionAction
public function inscriptionAction(Request $request)
{
$user = new Utilisateur();
$user->setConfirmation(gencode(10));
// On crée le FormBuilder grâce à la méthode du contrôleur
$formBuilder = $this->createFormBuilder($user);
// On ajoute les champs de l'entité que l'on veut à notre formulaire
$formBuilder->add('username', TextType::class, array('label' => 'Identifiant'))->add('password', RepeatedType::class, array('type' => PasswordType::class, 'invalid_message' => 'Les mots de passe doivent correspondre', 'options' => array('required' => true), 'first_options' => array('label' => 'Mot de passe'), 'second_options' => array('label' => 'Mot de passe (validation)')))->add('email', EmailType::class, array('label' => 'E-mail'))->add('fichierAvatar', VichImageType::class, array('required' => false, 'label' => 'Avatar'))->add('facebook', TextType::class, array('required' => false, 'label' => 'Facebook'))->add('twitter', TextType::class, array('required' => false, 'label' => 'Twitter'))->add('googlePlus', TextType::class, array('required' => false, 'label' => 'Google+'))->add('skype', TextType::class, array('required' => false, 'label' => 'Skype'))->add('nom', TextType::class, array('required' => false, 'label' => 'Nom'))->add('prenom', TextType::class, array('required' => false, 'label' => 'Nom'))->add('dateNaissance', DateType::class, array('required' => false, 'label' => 'Date de naissance', 'widget' => 'single_text', 'format' => 'dd MMMM y', 'attr' => array('class' => 'datepicker')))->add('nom', TextType::class, array('required' => false, 'label' => 'Prénom'))->add('adresse', TextType::class, array('required' => false, 'label' => 'Adresse'))->add('codePostal', TextType::class, array('required' => false, 'label' => 'Code postal'))->add('ville', TextType::class, array('required' => false, 'label' => 'Ville'))->add('telephone', TextType::class, array('required' => false, 'label' => 'Téléphone'))->add('acceptConditions', CheckboxType::class, array('required' => true, 'label' => 'J\'ai lu et j\'accepte les ', 'mapped' => false, 'attr' => array('class' => 'filled-in')));
// À partir du formBuilder, on génère le formulaire
$form = $formBuilder->getForm();
// On fait le lien Requête <-> Formulaire
// À partir de maintenant, la variable $user contient les valeurs entrées dans le formulaire par le visiteur
$form->handleRequest($request);
// On vérifie que les valeurs entrées sont correctes
if ($form->isValid()) {
// On encrypte le mot de passe
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($user);
$password = $encoder->encodePassword($user->getPassword(), $user->getSalt());
$user->setPassword($password);
// On enregistre notre objet $user dans la base de données
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
$message = \Swift_Message::newInstance()->setSubject('[Gatsun Site] Confirmation de l\'inscription')->setFrom('gatsun.radio@gmail.com')->setTo($user->getEmail())->setBody($this->renderView('GatsunWebsiteBundle:Utilisateur:emailConfirmation.html.twig', array('utilisateur' => $user)), 'text/html');
$this->get('mailer')->send($message);
// On redirige vers la page indiquant que le mail de confirmation vient d'être envoyé
return $this->render('GatsunWebsiteBundle:Utilisateur:inscriptionTerminee.html.twig', array('utilisateur' => $user));
}
// À ce stade :
// - Soit la requête est de type GET, donc le visiteur vient d'arriver sur la page et veut voir le formulaire
// - Soit la requête est de type POST, mais le formulaire n'est pas valide, donc on l'affiche de nouveau
// On passe la méthode createView() du formulaire à la vue afin qu'elle puisse afficher le formulaire toute seule
return $this->render('GatsunWebsiteBundle:Utilisateur:inscription.html.twig', array('form' => $form->createView()));
}
示例15: 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');
}