2013-01-10 4 views
7

나는 PHPMailer와 SMTP를 사용하는 방법을 알고 :PHPMailer 기본 구성 SMTP

$mail    = new PHPMailer(); 
$mail->IsSMTP(); // telling the class to use SMTP 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->Host  = "mail.yourdomain.com"; // sets the SMTP server 
$mail->Username = "[email protected]"; // SMTP account username 
$mail->Password = "yourpassword";  // SMTP account password 

을 그리고 그것을 잘 작동합니다. 하지만 내 질문은 :

메일을 보낼 때마다 지정할 필요가 없도록 PHPMailer가 기본적으로이 설정을 사용하도록 구성하려면 어떻게해야합니까?

+1

만약 wordpress에 관한 것이라면 -> wordpress \ wp-includes \ class-phpmailer.php 파일 – swapnesh

답변

14

함수를 만들고 포함하거나 사용하십시오.

function create_phpmailer() { 
    $mail    = new PHPMailer(); 
    $mail->IsSMTP(); // telling the class to use SMTP 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->Host  = "mail.yourdomain.com"; // sets the SMTP server 
    $mail->Username = "[email protected]"; // SMTP account username 
    $mail->Password = "yourpassword";  // SMTP account password 
    return $mail; 
} 

그리고 create_phpmailer()를 호출하여 새 PHPMailer 객체를 만듭니다.

또는 당신이 매개 변수를 설정 자신의 서브 클래스, 파생 할 수 있습니다

class MyMailer extends PHPMailer { 
    public function __construct() { 
    parent::__construct(); 
    $this->IsSMTP(); // telling the class to use SMTP 
    $this->SMTPAuth = true;     // enable SMTP authentication 
    $this->Host  = "mail.yourdomain.com"; // sets the SMTP server 
    $this->Username = "[email protected]"; // SMTP account username 
    $this->Password = "yourpassword";  // SMTP account password 
    } 
} 

을 새로운 MyMailer()를 사용합니다.

+0

class.phpmailer.php 파일을 편집 할 수 없습니까? 기본적으로 (최소한 현재 버전) 다음으로 시작합니다 :'class PHPMailer { public $ Version = '5.2.9'; public $ Priority = 3; public $ CharSet = 'iso-8859-1'; public $ ContentType = 'text/plain'; public $ Encoding = '8bit'; public $ ErrorInfo = ''; public $ From = '루트 @ 로컬 호스트'; public $ FromName = '루트 사용자';'... 그래서'$ From'의 값을'myname @ example.com'으로 변경하면 – koljanep

1

class.phpmailer.php 파일을 편집 할 수 없습니까?

클래스 파일 자체를 편집하지 않는 것이 가장 좋습니다. 코드를 유지 관리하기가 더 어렵 기 때문입니다. 직접 phpmailer 클래스를 수정 wp_mail 기능 자체의 소스에서

/** 
    * Fires after PHPMailer is initialized. 
    * 
    * @since 2.2.0 
    * 
    * @param PHPMailer &$phpmailer The PHPMailer instance, passed by reference. 
    */ 
    do_action_ref_array('phpmailer_init', array(&$phpmailer)); 

:

0

당신은이 훅을 사용할 수 있습니다.

+0

그 코덱스 페이지는 다음과 같습니다 : https :// /codex.wordpress.org/Plugin_API/Action_Reference/phpmailer_init – shahar