使用PHP Swiftmailer在Symfony的1.4的cron作业?
-
28-09-2019 - |
题
我使用的Symfony 1.4与行走作为ORM。我已经配置Web服务器调度触发每1小时邮件功能。发送邮件我使用PHP斯威夫特邮件类,而不是symfony中的inbuild Swiftmailer(默认1.3,1.4)。但在使用它给我的错误..
作为 “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
”。
我使用的代码...
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);
是否有任何其他的方式,通过Cron作业发送邮件??
解决方案
是。见1.4本书的相关部分:从发送电子邮件任务。
其他提示
此问题是因为你需要在TAKS添加此引用:
requiere_once dirname(__FILE__) . '/../vendor/symfony/lib/vendor/swiftmailer/swift_required.php
不隶属于 StackOverflow