标签: swiftmailer

使用Swift_Message发送邮件时如何更改发件人的名称文本?

我正在使用SwiftMailer从我的应用程序发送电子邮件.

到目前为止一切正常.我现在需要能够动态更改发件人的文本.下面的代码片段和下一段应该有希望澄清我的意思.

目前,我的代码如下所示:

try{
   $message = Swift_Message::newInstance()
               ->setFrom($from)
               ->setTo($to)
               ->setSubject($subject)
               ->setBody($content);

   $mailer->send($message);
}catch (Exception $e) {
   // do something ...
}
Run Code Online (Sandbox Code Playgroud)

$ from变量包含发件人的电子邮件地址 - 即sysmail@mydomain.com

但是,我想为不同的实体(例如论坛,组等)发送每日摘要(例如),因此我希望能够将发件人的姓名文本设置为"论坛ABC成员每日摘要",即使发件人仍然是sysmailer@mydomain.com.我注意到linkedin正在做类似的事情 - 他们在不同的发件人名下发送不同的摘要,即使发件人总是group-digests@linkedin.com.

sysmailer@mydomain.com的默认名称是"System Mailer".顺便说一句,我使用Google Apps作为我的邮件服务提供商.设置不同的用户帐户对我来说是不切实际的,因为用户可以创建自己的论坛等.

有没有一种方法可以动态地(即通过代码)指定发件人名称,尽管使用相同的发件人电子邮件地址?

php email swiftmailer

9
推荐指数
1
解决办法
6003
查看次数

laravel Mail :: failures()函数如何工作?

我一直试图获取没有使用laravel Mail::send()函数获取电子邮件的收件人列表.我正在尝试下面的代码.for循环用作因为每个用户都要收到自定义消息.

// First recipient is actual, the second is dummy.
$mail_to_users = ["original_account@domain.com","dummy_account@domain.com"];
$failures = [];

foreach($mail_to_users as $mail_to_user) {
   Mail::send('email', [], function($msg) use ($mail_to_user){
     $msg->to($mail_to_user);
     $msg->subject("Document Shared");
   });

   if( count( Mail::failures() ) > 0 ) {
      $failures[] = Mail::failures()[0];
   }
}

print_r($failures);
Run Code Online (Sandbox Code Playgroud)

我一直在尝试所有可能的选择.我将正确的邮件配置更改为错误的邮件配置config/mail.php.但是,如果我这样做,那么laravel显示错误页面,但$failure变量总是返回空.

php email swiftmailer laravel laravel-4

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

swiftmailer/swiftmailer 软件包已被废弃,您应该避免使用它。使用 symfony/mailer 代替

对于这种情况,我无法安装 breez 和 npm。我应该怎么做才能解决这个问题?当我要创建一个 laravel 项目时,也显示这个和 breez 安装时间。

控制台屏幕

swiftmailer laravel

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

如何在不使用命令的情况下从swiftmailer发送假脱机

如何在不使用命令的情况下从swiftmailer发送假脱机?

php app/console swiftmailer:spool:send --env=prod

我需要以某种方式将其放入php文件中,以便服务器管理员可以将其添加到Schedule.

spool swiftmailer symfony

8
推荐指数
2
解决办法
9384
查看次数

使用symfony 2的swift邮件程序,收到了一封电子邮件,但在电子邮件中得到了不必要的回复

通过电子邮件获得此响应"HTTP/1.0 200 OK缓存控制:无缓存内容类型:text/html; charset = UTF-8日期:星期二,2012年11月13日04:56:14 GMT".

这是我的代码:

 public function sendEmail($subject, $template, $templateParams)
    {
        $userEmail = $this->session->get('email');
        $name = $this->session->get('name');
        $adminEmail = $this->container;
        $templateParams['username'] = $name; 
        $message = \Swift_Message::newInstance()
                ->setSubject($subject)
                ->setFrom($adminEmail)
                ->setTo($userEmail)
                ->setBody($this->templating->render('SocialDonSocialBundle:Email:'.$template,$templateParams), 'text/html'); 
        $this->mailer->send($message);
Run Code Online (Sandbox Code Playgroud)

另请注意,此方法属于服务即"电子邮件".我创建了一个服务"电子邮件",负责发送电子邮件.有谁知道可能是什么问题?

swiftmailer symfony twig

8
推荐指数
1
解决办法
2512
查看次数

Symfony2控制器中没有捕获Swiftmailer异常

我正在使用Gmail帐户作为主机开发一个简单的邮件应用程序.它就像一个魅力,但当send()函数抛出异常时问题就出现了.我看到try catch语句无法处理异常.即使我使用Global异常类,它也不起作用.在某个地方也讨论过这个问题.

例如 :

在Symfony2 dev env控制器中捕获swiftmailer异常

要么

https://groups.google.com/forum/#!topic/symfony2/SlEzg_PKwJw

但他们没有达到工作的答案.

我的控制器功能代码是:

    public function ajaxRegisterPublisherAction()
    {

//some irrelevant logic

     $returns=  json_encode(array("username"=>$username,"responseCode"=>$responseCode));


    try{
            $message = \Swift_Message::newInstance()
        ->setSubject('hello world')
        ->setFrom('jafarzadeh91@gmail.com')
        ->setTo('jafarzadeh991@yahoo.com')
        ->setBody(
            $this->renderView('AcmeSinamelkBundle:Default:email.txt.twig',array('name'=>$username,"password"=>$password))
        );
      $this->container->get("mailer")->send($message);

    }
   catch (Exception $e)
    {

    }



    return new \Symfony\Component\HttpFoundation\Response($returns,200,array('Content-Type'=>'application/json'));


    }
Run Code Online (Sandbox Code Playgroud)

我在firebug控制台中收到的上述代码发送的响应是:

{"username":"xzdvxvvcvxcv","responseCode":200}<!DOCTYPE html>
<html>
    .
    .
Swift_TransportException: Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?]
    .
    .
</html>
Run Code Online (Sandbox Code Playgroud)

我抓住了我的头发,因为我不知道为什么内核在继续我的json对象时处理异常?

当我评论这一行时: …

php swiftmailer symfony

8
推荐指数
1
解决办法
2642
查看次数

来自Symfony Command的Swift邮件

我尝试使用Symfony命令从命令行发送Swift邮件.虽然我得到以下例外.

Fatal error: Call to undefined method Symfony\Bundle\TwigBundle\Debug\TimedTwigE
ngine::renderView() in ...
Run Code Online (Sandbox Code Playgroud)

一个容器被添加到这个类中,这是我从命令中获得的 ContainerAwareCommand

函数的代码看起来像这样:

private function sendViaEmail($content) {
    $message = \Swift_Message::newInstance()
            ->setSubject('Hello Email')
            ->setFrom('123@gmail.com')
            ->setTo('123@gmail.com')
            ->setBody(
            $this->container->get('templating')->renderView(
                    'BatchingBundle:Default:email.html.twig', array('content' => $content)
            )
    );
    $this->get('mailer')->send($message);
}
Run Code Online (Sandbox Code Playgroud)

更新 发生异常的行是$this->container->get('templating')->renderView(

正如你在代码中看到的那样,最后一行可能会失败,直到它最终到达那里.

php swiftmailer symfony

8
推荐指数
1
解决办法
5154
查看次数

Symfony 2.3:如何配置SwiftMailer自动使用自定义插件?

我已经创建了一个自定义的SwiftMailer插件,我想在我的Symfony 2.3应用程序中默认使用SwiftMailer.我在这方面可以找到的唯一文档是:http://symfony.com/doc/current/reference/dic_tags.html#swiftmailer-plugin

我已按如下方式设置服务:

acme_test_bundle.swiftmailer.embed_images:
    class: Acme\TestBundle\SwiftMailer\Plugins\ImageEmbedPlugin
    tags:
        - { name: swiftmailer.plugin }
Run Code Online (Sandbox Code Playgroud)

即使已经创建了此服务,SwiftMailer也没有使用该插件.我做错了什么,还有什么我应该做的吗?

php swiftmailer symfony symfony-2.3

8
推荐指数
1
解决办法
1521
查看次数

类Illuminate\Mail\Message的对象无法转换为字符串

我正在使用Laravel 5.5试图发送电子邮件但收到错误

类Illuminate\Mail\Message的对象无法转换为字符串

这是我的控制器

public function contactreply($contact, Request $request){
    $reply = new Reply;
    $reply->subject = $request->subject;
    $reply->message = $request->message;
    $reply->email = $contact;
    $reply->save();
    $mail = Mail::to($contact)->send(new ContactReply($reply));
    return Redirect::back()->with('status', 'Email Sent Success');
}
Run Code Online (Sandbox Code Playgroud)

这是我的ContactReply.php

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class ContactReply extends Mailable
{
    use Queueable, SerializesModels;

    protected $reply;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($reply)
    {
       $this->reply = $reply; //dd($reply) passing all value here
    } …
Run Code Online (Sandbox Code Playgroud)

php email swiftmailer laravel laravel-5.5

8
推荐指数
2
解决办法
3700
查看次数

我可以在SwiftMailer中使用传统的电子邮件“收件人”行吗?

SwiftMailer需要一个电子邮件地址数组,其中可能包含名称作为该数组的值:

$message->setTo([
  'person1@example.org',
  'person2@example.net' => 'Person 2 Name',
  'person3@example.org',
  'person4@example.org',
  'person5@example.org' => 'Person 5 Name'
]);
Run Code Online (Sandbox Code Playgroud)

但是我只有一行文本,形成一个标准的To标题:

person1@example.org, 'Person 2 Name' <person2@example.net>, person3@example.org, person4@example.org, 'Person 5 Name' <person5@example.org>
Run Code Online (Sandbox Code Playgroud)

我可能可以一起破解一些东西,以将To标头转换为数组,但这似乎是标准解决方案的问题,理想情况下,这是来自吸收了RFC并会接受奇怪但有效的电子邮件地址的人,包括那些包含逗号和分号。SwiftMailer本身是否具有此功能?如果是这样,我找不到。

php email swiftmailer

8
推荐指数
1
解决办法
127
查看次数

标签 统计

swiftmailer ×10

php ×7

symfony ×5

email ×4

laravel ×3

laravel-4 ×1

laravel-5.5 ×1

spool ×1

symfony-2.3 ×1

twig ×1