2011-03-21 3 views
3

PHPMailer를 사용하여 수신자에게 개별 이메일을 보내려면 $mail->SingleTo = TRUE;을 내 코드에 추가 할 때 받는 사람 : 필드에 아무것도 표시되지 않습니다.개별 이메일에 대한 PHPMailer 설정이 비어 있습니다.받는 사람 : 입력란

$mail->SingleTo = TRUE;을 제거하면 받는 사람 : 필드에 정확한 전자 메일 주소가있는 전자 메일이 발송됩니다.

내가 무엇을 얻을 수 있습니다 :

reply-to  xxxxxx <[email protected]>, No Reply <[email protected]> 
to  
date   Mon, Mar 21, 2011 at 5:07 PM 
subject  Testing  
mailed-by gmail.com 
signed-by gmail.com 

(XXXXXXX 내 이메일 주소를 나타냅니다.)

여기

내 코드입니다 :

if(isset($_POST['submit'])) 
{ 
    require_once('PHPMailer_v5.1/class.phpmailer.php'); 


$mail   = new PHPMailer(); 

$subject = $_POST['subject']; 
$body = $_POST['emailbody']; 
$to   = $_POST['to']; 



$mail->IsSMTP(); // telling the class to use SMTP 
//$mail->Host  = "localhost"; // SMTP server 
$mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
              // 1 = errors and messages 
              // 2 = messages only 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->SMTPSecure = "SSL";     // sets the prefix to the servier 
$mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
$mail->Port  = 587;     // set the SMTP port for the GMAIL server 
$mail->Username = "[email protected]"; // GMAIL username 
$mail->Password = "*********";   // GMAIL password 

$mail->SetFrom('[email protected]', 'XXXXXX'); 

$mail->AddReplyTo("[email protected]","No Reply"); 

$mail->Subject = $subject; 

// After adding this line I'm getting an empty To: field 
$mail->SingleTo = TRUE; 

$mail->AddAddress("[email protected]", 'xyz abc'); 
$mail->AddAddress("[email protected]", 'abc xyz'); 
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 

$mail->MsgHTML($body); 


if(!$mail->Send()) { 
    $message= "Mailer Error: " . $mail->ErrorInfo; 
} 
else 
{ 
    $message= "Message sent!"; 
}  
} 
+0

질문이 접수되었지만 현상금이 열려 있습니까? 우리가 왜 현상금에 대한 답을 얻을 수 있을까요? –

답변

3

전자 메일을 보내기 위해 SMTP를 사용하고 있습니다. Phpmailer 클래스는 Smtp를 사용하여 전송할 때 SingleTo 매개 변수를 사용하지 않습니다.

더 많은 경우, SingleTo == true 인 경우 CreateHeader 함수가 표시되는 경우받는 사람은 $ this-> SingleToArray에만 적용되며 헤더 자체에는 적용되지 않으므로 기본적으로 PHPmailer 버그가 발생합니다.

는 phpmailer을 패치하지 않으려면

솔루션

function & prepare_mailer($subject, $body) { 

    $mail   = new PHPMailer(); 
    $mail->IsSMTP(); // telling the class to use SMTP 
    //$mail->Host  = "localhost"; // SMTP server 
    $mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
               // 1 = errors and messages 
               // 2 = messages only 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->SMTPSecure = "SSL";     // sets the prefix to the servier 
    $mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
    $mail->Port  = 587;     // set the SMTP port for the GMAIL server 
    $mail->Username = "[email protected]"; // GMAIL username 
    $mail->Password = "*********";   // GMAIL password 
    $mail->SetFrom('[email protected]', 'XXXXXX'); 
    $mail->AddReplyTo("[email protected]","No Reply"); 
    $mail->Subject = $subject; 
    $mail->MsgHTML($body); 
    return $mail; 
} 

foreach($_POST['to'] as $to){ 
    $mail = null; 
    $mail = & prepare_mailer($_POST['subject'],$_POST['body']); 
    $mail->AddAddress($to['address'], $to['name']); 
    $mail->Send(); 

} 
+0

흠 .. 고마워 .. 문제가 smtp의 원인이라면이 클래스의 메일 기능을 사용하면 내가 원하는대로 이메일을 보낼 수 있습니까? – mysterious

+0

smtp를 yes로 사용하지 않으면 IsMail()을 사용하고 서버 (PHP)에서 메일을 가져야합니다. 예 : [mail] (http://phpmailer.worxware.com/index.php?pg=examplebmail) 또는 [sendmail] (http://phpmailer.worxware.com/index.php?pg=examplebsendmail) –

+1

감사합니다. 내가 그 프로젝트에서 다시 일할 때 해봐. – mysterious

0

이 문제는 SmtpSend 기능에 있습니다 (시작 class.phpmailer.php의 701 행). 거기에서 볼 수 있듯이 singleTo 설정을 고려하지 않고 모든받는 사람을 추가하고 메시지 본문을 한 번만 보냅니다.

그래서 거기에 논리를 추가하여 singleTo가 true인지 테스트하고이 메일을 별도로 보내도록 코드를 수정하여 To : 헤더의 접두어를 메시지 본문에 추가해야합니다. singleTo가 false이면 코드를있는 그대로 호출 할 수 있습니다 (줄 713 - 758).

또는 패치하지 않으려는 경우 singleTo 매개 변수를 지원하는 것으로 보이는 전송 방법 (예 : sendmail)을 사용할 수 있습니다.

+0

나는 smtp 대신에 php mailer의 메일 기능 옵션을 사용하고 싶습니다. – mysterious

0

$ 메일 -> AddAddress 될 것입니다, SingleTo 속성을 사용하지 않고 이메일 하나씩을 보내는 것입니다, 유일한 선택 것 같은데() 당신이 그렇다면 CSV의 을 좋아하지 않는다 :

$Emails="[email protected],[email protected]"; #etc; 

는 분할 후 루프를 수행합니다

- BF.

3

다른 모든 매개 변수를 설정 한 다음 루프에서 수신자를 설정하고 전자 메일을 보낸 다음 ClearAllRecipients() 함수를 사용하십시오. 좋아요 :

{ // loop start 
     $mail->AddAddress($person_email, $person_name); 
     $mail->Send(); 
     $mail->ClearAllRecipients(); 
} // loop end 
0

싱글 토글 좋은 생각이 아닙니다. SMTP가 아닌 "센드 메일"또는 "메일"전송에서만 작동합니다. SMTP와 함께 SingleTo를 사용하는 경우,이 매개 변수는 오류나 경고없이 무시되며 중복을 얻을 수 있습니다.

코드에 표시된 것처럼 SingleTo SMTP를 모두 사용하므로 사용자의 경우 SingleTo가 무시됩니다.

SMTP 프로토콜은 하나의 메시지를 TO : 필드에 고유 한 주소 만 가진 여러 다른받는 사람에게 보낼 수 없도록 디자인되었습니다. 각 수신자에게 TO :에있는 이름 만 갖게하려면 전체 메시지를 다시 전송해야합니다. 이것은 SingleTo가 SMTP와 호환되지 않는 이유를 설명합니다.

PHPMailer 라이브러리 작성자에 따르면 SingleTo는 PHPMailer 6.0 릴리스에서 더 이상 사용되지 않으며 7.0에서 제거 될 예정입니다. 필자는 PHPMailer가 메일 링리스트 발신자가 아니기 때문에 더 높은 수준의 여러 수신자에게 보내는 것을 제어하는 ​​것이 더 낫다고 설명했습니다. 그들은 PHP mail() 함수의 사용은 안전하게 사용하기가 매우 어렵 기 때문에 권장하지 않는다. SMTP는 빠르고 안전하며 더 많은 제어 및 피드백을 제공합니다. SMTP가 SingleTo와 호환되지 않기 때문에 PHPMailer 작성자는 SMTP가 아닌 SingleTo를 제거합니다.

관련 문제