在 Symfony 1.4 的 Cron 作业中使用 PHP Swiftmailer?
我使用 Symfony 1.4 和 Propel 作为 ORM。我已将 Web 服务器调度程序配置为每 1 小时触发一次邮件功能。为了发送邮件,我使用 PHP Swift 邮件程序类,而不是 symfony 的内置 Swiftmailer(1.3、1.4 中默认)。但在使用它时给我错误.. 作为“可捕获的致命错误:传递给 Swift_Transport_EsmtpTransport::__construct() 的参数 1 必须实现接口 Swift_Transport_IoBuffer,/home/msconslt/sfprojects/test/lib/mailClasses/classes/Swift/Transport/EsmtpTransport.php 中没有给出第 64 行
”。 我正在使用的代码...
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('[email protected]')
->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('[email protected]' => 'Harry'))
->setTo(array('[email protected]'))
->setBody('<html>'.
'<head></head>'.
'<body> <span>Dear, </span><br/> Hi there..</body>'.
'</html>',
'text/html'
);
$mailer->send($message);
还有其他方法可以通过 Cron 作业发送邮件吗?
I am using Symfony 1.4 with 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('[email protected]')
->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('[email protected]' => 'Harry'))
->setTo(array('[email protected]'))
->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??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。请参阅 1.4 书的相关部分: 从以下位置发送电子邮件一个任务。
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 :