我使用Symfony 1.4和Propel作爲ORM。我已經配置了web服務器調度程序,以便在每個1Hour觸發郵件功能。發送郵件我使用PHP Swift郵件類,而不是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
」。 是我使用的代碼...在Symfony 1.4的Cron Jobs中使用PHP Swiftmailer?
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作業發送郵件?
感謝@Maerlyn – 2010-11-02 12:36:26