2011-12-15 7 views
0

私は今、クラスのインスタンス内でそれを含めるはSwift_Mailクラスのインスタンス

//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('[email protected]') 
    ->setBody('Here is the message itself'); 
//Send the message 
$result = $mailer->send($message); 

正常に動作し、次のテストは、(例えば、オブジェクト内の関数が迅速使用して電子メールを送信)しているを作ります。私はリファクタリングする必要があることを知っているが、私はその点を見逃している。それは間違っているのですが、私は

$メーラー=の$ this - > Swift_Mailer ::のnewInstance($輸送)の線に沿って何かを言おうとイムを推測します。

しかし、私はリファクタリング方法を見ることができません。手伝ってくれますか? おかげ ジャイルズ

+0

私はこのような場合は、あなたの最初の例とは異なるように持っているか表示されません。 まず、コードにswift mailerクラスを組み込み、次にスウィフトオブジェクトをインスタンス化します。それは簡単です。 – Khronos

+0

私はこのことをどうやって分かりませんか - あなたは説明できますか? – giles

+0

下記の答えを確認してください。あなたの例です。 – Khronos

答えて

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('[email protected]') 
     ->setBody('Here is the message itself'); 
     //Send the message 
     $result = $mailer->send($message); 
    } 

} 
関連する問題