标签: swiftmailer

加载自定义Yii组件

我正在尝试使用我创建的自定义类来发送邮件,以便我可以保持控制器文件很薄.我创建了自定义类并将其放在components文件夹中.然后我补充说:

'sendMail' => array(
    'class'=>'application.components.SendMail.',
), 
Run Code Online (Sandbox Code Playgroud)

在我的主配置文件中的主要组件下面.

这应该允许我直接访问类正确吗?我尝试使用:

Yii::app()->SendMail->MailerConfirmation();
Run Code Online (Sandbox Code Playgroud)

和:

Yii:app()->MailerConfirmation();
Run Code Online (Sandbox Code Playgroud)

而我最终得到的只是错误.

谁能告诉我如何包含自定义组件?也许我这样做错了?

php swiftmailer yii

7
推荐指数
1
解决办法
1万
查看次数

Swiftmailer // Twig电子邮件无法正确呈现

我正在尝试使用symfony2框架,我正在尝试使用swiftmailer和twig发送电子邮件.问题是,在我目前的实现中,电子邮件是用html发送的(你可以看到标签,一切).

这是我正在使用的控制器:

 public function formularioAction()
{   
    $enquiry = new Enquiry();
    $form = $this->createForm(new EnquiryType(), $enquiry);

    $request = $this->getRequest();
    if($request->getMethod() == 'POST'){
        $form->bindRequest($request);

        if($form->isValid()){

            $message = \Swift_Message::newInstance()
                    ->setSubject('Mail from the App')
                    ->setFrom('no-reply@app.com')
                    ->setTo('******@gmail.com')
                    ->setBody($this->render( 'AcmeDemoBundle:Demo:email.html.twig' ));

            $this->get('mailer')->send($message);
            //end of mail sending

            //redirect - it's important to prevent users from reposting the form if
            //they refresh the page
            return $this->redirect($this->generateUrl( '_formulario'));
        }
    }
    return $this->render('AcmeDemoBundle:Demo:formulario.html.twig', array('form' => $form->createView()));
}
Run Code Online (Sandbox Code Playgroud)

电子邮件使用的树枝模板:

{% extends "AcmeDemoBundle::layout.html.twig" %}

{% block title "Email de teste" %}

{% …
Run Code Online (Sandbox Code Playgroud)

swiftmailer symfony twig

6
推荐指数
1
解决办法
7828
查看次数

异步发送电子邮件:spool,queue和cronjob/daemon

我想异步发送电子邮件以获得更快更轻的http响应,但我正在努力解决许多新概念.

例如,文档讨论了spool.它说我应该将spool与文件一起使用,然后使用命令发送电子邮件.但是我应该如何运行该命令呢?如果我设置cronjob每1分钟执行一次该命令(可用的最小值cron),用户将不得不平均等待30秒才能发送电子邮件(例如,注册电子邮件).

所以我想改用队列.我已经在使用RabbitMQBundle进行图像处理(例如缩略图创建).但是我只是定期使用这个,所以它是从cronjob中消耗掉的.

也许我应该创建一个始终等待新邮件到达电子邮件队列并尽快交付的守护进程

daemon amqp swiftmailer rabbitmq symfony

6
推荐指数
1
解决办法
3375
查看次数

Symfony2中的Swiftmailer的多个实例

Symfony2使用Swiftmailer包发送电子邮件.

要在Symfony2中使用和配置Swiftmailer,必须使用文档中说明的配置,例如使用YAML:

swiftmailer:
    transport:  smtp
    encryption: ssl
    auth_mode:  login
    host:       smtp.gmail.com
    username:   your_username
    password:   your_password
Run Code Online (Sandbox Code Playgroud)

Swiftmailer在Symfony2中定义为服务,它的实例可以在控制器中获得,如下所示:

$mailerinstance = $this->get('mailer');
Run Code Online (Sandbox Code Playgroud)

现在,让我们假设Swiftmailer需要两种不同的配置,例如使用电子邮件假脱机(例如用于预定的时事通讯)和另一种立即发送所有新电子邮件(例如用于密码丢失服务)的配置.因此,我想应该定义Swiftmailer的两个独立实例.我怎么能在Symfony2中做到这一点?

swiftmailer symfony

6
推荐指数
1
解决办法
1719
查看次数

Symfony2 Monolog到电子邮件错误为什么swiftmailer.transport.real不存在

从更新symfony后2.32.4我得到了ServiceNotFoundException

 Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException' with message 'The service "monolog.handler.mojhandler" has a dependency on a non-existent service "swiftmailer.transport.real".' in E:\wamp\www\project\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass.php on line 59
Run Code Online (Sandbox Code Playgroud)

这是我的config_prod.yml

imports:
    - { resource: config.yml }
monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      streamed
        streamed:
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug
        mail:
            type:         fingers_crossed
            action_level: error
            handler:      buffered
            channels: ["!app"] # Dont log app because we dont' want 404 errors sending
        buffered:
            type:    buffer
            handler: mojhandler
        mojhandler:
            type:       swift_mailer …
Run Code Online (Sandbox Code Playgroud)

php service swiftmailer symfony

6
推荐指数
2
解决办法
3177
查看次数

附加并发送文件后如何取消链接?(使用 Mail::queue 时)

我从立即发送邮件切换到将它们添加到队列中,这是我的代码,这$attachments是一个临时路径数组,我已经注释掉了我尝试过的内容,这会引发有关文件不存在的错误。

Mail::queue($view, $data, function(\Illuminate\Mail\Message $message) use($mail,$attachments){
    foreach($mail->getRecipients() as $recipient){
        $message->to($recipient);
    }
    $message->subject($mail->getSubject());
    foreach($attachments as $attachment){
        $message->attach($attachment);
        //this deletes the attachment before being sent
        //unlink($attachment);
    }
});
/* This code only works when using Mail::send() instead of Mail:queue()
foreach($attachments as $attachment){
    unlink($attachment);
}
*/
Run Code Online (Sandbox Code Playgroud)

基本上我想在邮件发送后清理和删除我的临时附件。我猜这不适用于开箱即用的 laravel 邮件解决方案。如何触发代码post-queue-mail-sent

php swiftmailer laravel-4

6
推荐指数
2
解决办法
2569
查看次数

如何在 monolog 中使用 swiftmailer 处理程序

我想知道如何SwiftMailerHandlerMonologpackagist 中使用?
Monolog文档中,我没有看到任何使用示例,SwiftMailerHandler或者我可能错过了。
下面是SwiftMailerHandler构造函数代码:

/**
 * @param \Swift_Mailer           $mailer  The mailer to use
 * @param callable|\Swift_Message $message An example message for real messages, only the body will be replaced
 * @param integer                 $level   The minimum logging level at which this handler will be triggered
 * @param Boolean                 $bubble  Whether the messages that are handled can bubble up the stack or not
 */
public function __construct(\Swift_Mailer $mailer, $message, $level = Logger::ERROR, …
Run Code Online (Sandbox Code Playgroud)

php handlers swiftmailer monolog

6
推荐指数
1
解决办法
2694
查看次数

使用队列时的 Laravel 邮件回调

有没有办法将回调函数传递给 Laravel 的邮件程序?

我正在使用Mail带有可邮寄类的外观,该类正在发送附件。发送电子邮件后,我想删除附加的文件表单存储。

电子邮件作业正在排队

Mail::to($user)->send(new MyMailable($file));
Run Code Online (Sandbox Code Playgroud)

我无法使用 Mailer 触发事件(https://laravel.com/docs/5.4/mail#events)。原因之一,因为该事件发生在发送电子邮件之前,这意味着我当时无法删除该文件,或者该邮件将没有附件。其次,该应用程序有多个电子邮件作业,有些必须删除附件,有些则不需要。事件数据swiftmailer只有实例,没有关于作业本身的额外信息(例如可邮寄的数据)。

swiftmailer laravel laravel-5.4

6
推荐指数
1
解决办法
1115
查看次数

使用 swiftmailer 向多个收件人发送电子邮件

我正在尝试在我的项目中使用 swiftmailer,以便我可以向多个用户发送 html 时事通讯。我已经彻底搜索过,但我所得到的一切都没有为我工作。我想在以逗号分隔的表单输入字段中粘贴多个收件人并将 html 电子邮件发送给他们。我将收件人设置为一个变量($recipients_emails)并将其传递给发送代码中的 setTo() 方法,与html_email.

问题是: Q1 如何从收件人输入字段发送给多个收件人。

我试过这个:

if (isset($_POST['recipients_emails'])) {
    $recipients_emails  = array($_POST['recipients_emails'] );
    $recipients_emails= implode(',',$recipients_emails);
}
Run Code Online (Sandbox Code Playgroud)

Q2 如何在 heredoc 标签中制作 Html。当我尝试像这样连接时->setBody('<<<EOT'.$html_email.'EOT;', 'text/html');,我的消息会与 heredoc 标签一起出现。

if (isset($_POST['html_email'])) {
    $html_email = $_POST['html_email'];
}
Run Code Online (Sandbox Code Playgroud)

我如何$_POST['html_email'];在 EOT 标签内输入;

这是 swiftmailer 发送脚本的一部分;

$message = Swift_Message::newInstance()
        ->setSubject($subject)
        ->setFrom($from)
        ->setTo($recipients_emails)
        ->setBody($html_email, 'text/html');
Run Code Online (Sandbox Code Playgroud)

注意:我还在学习这些东西。

php forms email newsletter swiftmailer

6
推荐指数
2
解决办法
1万
查看次数

如何通过 Swift 邮件程序添加标题

我正在尝试向通过 swift mailer 发送的消息添加标题。

$message = Swift_Message::newInstance($title)
          ->setFrom(array('mail@mail.com' => 'Name'))
          ->setTo(array($email => $email))
          ->setBody($content, 'text/html');
Run Code Online (Sandbox Code Playgroud)

试过了,返回错误

 $message-> addTextHeader('List-Unsubscribe', $url_unsub);
Run Code Online (Sandbox Code Playgroud)

这返回什么都不做,但也不会返回错误

$headers = $message->getHeaders();
$headers->addTextHeader('List-Unsubscribe', $url_unsub);      
$result = $mailer->send($message); 
Run Code Online (Sandbox Code Playgroud)

知道该怎么做吗?

php swiftmailer smtpclient

6
推荐指数
1
解决办法
3910
查看次数