我有以下测试工作正常
//Create the Transport
$mailer = Swift_Mailer::newInstance($transport);
// create the message
$message = Swift_Message::newInstance('Hello World')
->setFrom(array(MAIL_FROM => MAIL_FROM_NAME))
->setTo(array('MyEmail@email.com')
->setBody('Here is the message itself');
//Send the message
$result = $mailer->send($message);
我现在想要将它包含在类实例中(例如,对象内的函数使用swift发送电子邮件)。我知道我必须重构,但我忽略了这一点。虽然这是错的,但我想我试图说出一些与
相似的话$ mailer = $ this-> Swift_Mailer :: newInstance($ transport);
但我看不出如何重构。你能帮我吗? 谢谢 贾尔斯
答案 0 :(得分:0)
inlcude 'swiftmailer.class.php;
class YourClass {
function __construct() {}
function yourFunction() {
$mailer = Swift_Mailer::newInstance($transport);
// create the message
$message = Swift_Message::newInstance('Hello World')
->setFrom(array(MAIL_FROM => MAIL_FROM_NAME))
->setTo(array('MyEmail@email.com')
->setBody('Here is the message itself');
//Send the message
$result = $mailer->send($message);
}
}