2011-12-15 5 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); 

잘 작동 다음과 같은 시험 (예를 들어 객체 내부의 기능은 신속한 사용하여 전자 메일을 보냅니다) 한 만들기. 나는 리팩토링해야한다는 것을 알고 있지만, 나는 그 요점을 놓치고있다. 그것이 틀린 동안, 나는 회선을 따라 무언가를 말하려고 노력하고 있다고 생각한다.

$ mailer = $ this-> Swift_Mailer :: newInstance ($ transport);

하지만 리팩터링 방법을 볼 수 없습니다. 도울 수 있니? 감사 자일스

+0

나는이 경우 첫 번째 예에서 다를 수있다 표시되지 않습니다. 먼저 코드에 신속 메일러 클래스를 포함시킨 다음 신속 객체를 인스턴스화합니다. 간단합니다. – 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); 
    } 

}