Php 创建Swift\u邮件类实例
我做了以下测试,效果很好Php 创建Swift\u邮件类实例,php,oop,swiftmailer,Php,Oop,Swiftmailer,我做了以下测试,效果很好 //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.co
//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\u mailer::newInstance($transport)
但我不知道如何重构。你能帮忙吗?
谢谢
贾尔斯我看不出这个案例与你的第一个例子有什么不同。首先在代码中包含swift邮件程序类,然后实例化swift对象。很简单。我不清楚这是怎么做到的-你能举例说明吗?检查下面的答案。这是你的例子。
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);
}
}