2013-03-06 2 views
1

전자 메일을 보내는 데 사용할 클래스를 만들었지 만 배 구성 요소를 통합하면 실패합니다.PHP 배 메일이 개체로 작동하지 않습니다.

는 "로컬 호스트에 연결하지 못했습니다 : 25 SMTP를 : 소켓을 연결하지 못했습니다 : 연결이 거부 (코드 : -1 응답 :)]"

이 절차 버전은 OOP 버전을 완벽하게 실행,하지만. 구조물에 Mail.php을 필요로하는 것이 가장 좋은 방법이다하지만 내가 또 다른 문제를 해결하기 위해 찾을 수있는 유일한 방법 인 경우

이 절차 버전 템플릿이 여기에

here을 찾을 수 있습니다 나의 클래스

class Email{ 

    private $_from; 
    private $_to; 
    private $_subject; 
    private $_body; 
    private $_headers; 

    # final 
    private $_host = "ssl://smtp.gmail.com:465"; 
    private $_username = "[email protected]"; 
    private $_password = "mypass"; 

    function __construct() 
    { 
     require_once("Mail.php"); 
    } 

    public function setup($from,$to,$subject,$body) 
    { 
     $this->_from = $from; 
     $this->_to  = $to; 
     $this->_subject = $subject; 
     $this->_body = $body; 

    } 
    public function send() 
    { 
     if(isset($this->_from) && isset($this->_to) && isset($this->_subject) && isset($this->_body)) 
     {    
      $this->_headers = array ('From' => $this->_from, 'To' => $this->_to,'Subject' => $this->_subject); 
      $smtp = Mail::factory('smtp',array ('host' => $_host, 
      'auth' => true, 
      'username' => $_username, 
      'password' => $_password)); 

      $mail = $smtp->send($this->_to, $this->_headers, $this->_body); 

      if (PEAR::isError($mail)) { 
       $_POST['mail_error'] = $mail->getMessage(); 
       return false; 
      } else { 
       return true; 
      } 
     } 
     else 
     { 
      $_POST['mail_error'] = "missing a required arguement"; 
      return false; 
     } 
    } 
} 

확실하지 않다 이 전에 연결 오류가 발생했습니다.

+2

'$ _host','$ _username'과'$ _password'를' 메일 :: 공장'전화. 나는 당신이'$ this -> _ host','$ this -> _ username'과'$ this -> _ password'를 의미한다고 생각합니다. –

+0

DOH !!! 고맙습니다! – Zachary

+0

@ColinMorelli : OP가 답변을 수락 할 수 있도록 답변으로 게시해야합니다. – Nikola

답변

0

Mail :: factory 호출에서 $ _host, $ _username 및 $ _password를 사용하고 있기 때문입니다. $ this -> _ username과 $ this -> _ password를 의미한다고 생각합니다. 콜린 모렐리

관련 문제