나는 내 메일 링리스트에서 txt 파일로 이메일 주소를 가져오고 있습니다. 다음과 같습니다 :PHP로만 BCC 메일 보내기
clearstatcache();
$file = file("test.txt");
for ($i = 0; $i < 20; $i++) {
$emails .= $file[$i];
}
나는 $ emails에 저장했습니다. 숨은 보내기 이제 등 [email protected], [email protected], [email protected]
을 : 나는 $ 이메일을 에코 경우, 나는 이메일을 열거 얻을
// recipient
$to = '';
// subject
$subject = 'The subject is here';
// message
$message = 'The body of the email is here';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: John Doe <[email protected]>' . "\r\n";
$headers .= 'Bcc: '.$emails . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
메일이 목록으로 전송되지 않고 [email protected]으로 전송됩니다. 따라서 작동하지 않고 예기치 않은 일이 발생합니다. for 루프의 20 개의 이메일이 이메일 상단에 나열됩니다. 본문 수신 [email protected]
수동 입력을 시도하면 완벽하게 작동합니다. 그래서 아래의 코드는 작동하지만, 수동 입력은 내가 달성하고자하는 것에 역효과가 있습니다.
$test = "[email protected], [email protected], [email protected],";
// recipient
$to = '';
// subject
$subject = 'The subject is here';
// message
$message = 'The body of the email is here';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: John Doe <[email protected]>' . "\r\n";
$headers .= 'Bcc: '.$test . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
는 그래서 문제가 변수에 나타납니다,하지만 난 $ 이메일을 잘 모든 이메일 주소를 메아리 때문에 작동하지 않는 이유를 알아낼 수 없습니다.
텍스트 파일의 정확한 실제 내용은 무엇입니까? 나는 그것을 읽는 방법론이 실수로 헤더 블록을 종료하고 본문을 시작하는 문자열 안의 빈 줄을 만들어 낼 것이라고 추측합니다. 더 간단한 방법은'implode (','file ('test.txt'))'를하는 것입니다. 'file()'함수는 배열에서 행을 읽고,'implode()'는 쉼표로 묶는다. –
쉼표 사이에 공백없이'$ test = "info @ example.com, test @ mydomain.com, admin @ domain.com을 사용하십시오 –
@MichaelBerkowski가 말한 것 위에 다음을 읽어보십시오. http :// /stackoverflow.com/a/9525476/2518525 – Darren