开发者

Symfony Swift Mailer : newInstance() is not taking variable

 $message = Swift_Message::newInstance('Testing') 

Here, when I pass a variable to newInstance() method, a mail is not sent.

 $var ='Testing';
 $message =开发者_JS百科 Swift_Message::newInstance($var) 

Can anyone please explain me this?

Also in Symfony framework swiftmailer is working only in actions.php. Why is it so?


Use the following to send an email using Symfony and SwiftMailer :

    $message = $this->getMailer()->compose(
      array('from@address.com' => 'From Name'),
      'to@address.com,
      'Subject',
      <<<EOF
      The body of the mail
      EOF
    );

    $this->getMailer()->send($message);

The compose() method takes four arguments and returns an email message object:

the sender email address (from); the recipient email address(es) (to); the subject of the message; the body of the message.

Sending the message is then as simple as calling the send() method on the mailer instance and passing the message as an argument. As a shortcut, you can only compose and send an email in one go by using the composeAndSend() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜