开发者

use PHP Swiftmailer in Symfony 1.4's Cron Jobs?

I am using Symfony 1.4 w开发者_如何学JAVAith Propel as ORM. i have configured web server schedulers to trigger a mailing function at every 1Hour. To send mails i am using PHP Swift mailer class, and not the symfony's inbuild Swiftmailer(default in 1.3,1.4). But while using it is giving me error.. as "Catchable fatal error: Argument 1 passed to Swift_Transport_EsmtpTransport::__construct() must implement interface Swift_Transport_IoBuffer, none given in /home/msconslt/sfprojects/test/lib/mailClasses/classes/Swift/Transport/EsmtpTransport.php on line 64". The code that i am using...

  require_once(dirname(__FILE__).'/../../config/ProjectConfiguration.class.php');
  $configuration =ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
  // Remove the following lines if you don't use the database layer
  $databaseManager = new sfDatabaseManager($configuration);

 //Create the Transport
 $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
 ->setUsername('myid@gmail.com')
 ->setPassword('mypassword')
 ;

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

 //Create a message
 $message = Swift_Message::newInstance("Test Mail")
 ->setFrom(array('myid@gmail.com' => 'Harry'))
->setTo(array('someid@gmail.com'))
->setBody('<html>'.
 '<head></head>'.
 '<body> <span>Dear, </span><br/> Hi there..</body>'.
 '</html>',
 'text/html'
 );

 $mailer->send($message);

is there any other way to send mail through Cron jobs??


Yes. See the relevant part of the 1.4 book: Sending an email from a task.


This problem is because you need add this reference in your taks :

 requiere_once dirname(__FILE__) . '/../vendor/symfony/lib/vendor/swiftmailer/swift_required.php
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜