Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony SwiftMailer,将setFrom设置为变量_Symfony_Swiftmailer - Fatal编程技术网

Symfony SwiftMailer,将setFrom设置为变量

Symfony SwiftMailer,将setFrom设置为变量,symfony,swiftmailer,Symfony,Swiftmailer,我使用的是Symfony2框架,我想基于setFrom作为变量发送邮件 我的意思是,我想替换: ->设置自('send@example.com") 借 顺便说一下,我尝试了这个解决方案,它适用于发件人和内容,但不适用于发件人: $from=$request->get('from'); $message= \Swift_Message::newInstance() ->setSubject($subject) ->

我使用的是Symfony2框架,我想基于
setFrom
作为变量发送邮件

我的意思是,我想替换: ->设置自('send@example.com")

顺便说一下,我尝试了这个解决方案,它适用于发件人和内容,但不适用于发件人:

    $from=$request->get('from');
    $message= \Swift_Message::newInstance()
             ->setSubject($subject)
             ->setFrom($from)
             ->setTo($to)
             ->setBody($content);
    $mailer->send($message);   
它只适用于文件“parameters.yml”中提到的邮件


感谢您的帮助

尝试按如下方式传递数组:

        $mailMessage = \Swift_Message::newInstance()
            ->setTo($to)
            ->setSubject($this->subject)
            ->setFrom(array($this->senderAddress=>$this->senderName))
            ->setBody($body ,$contentType);

更多信息

嗨,埃姆娜,你解决了吗?怎样?谢谢分享你的经验
        $mailMessage = \Swift_Message::newInstance()
            ->setTo($to)
            ->setSubject($this->subject)
            ->setFrom(array($this->senderAddress=>$this->senderName))
            ->setBody($body ,$contentType);