많은 사람에게 보내기
PHP 메일에서 CC, BCC 및 여러 수신자를 추가하는 방법에 대한 자습서에 오신 것을 환영합니다. PHP 메일 기능은 한 명의 수신자 만 받아들이는 것처럼 보이지만 실제로는 많은 사람들에게 동시에 보낼 수 있습니다.
그러나 우리는 어떻게 합니까? 이 안내서에서 예제를 통해 살펴볼 내용입니다. 계속 읽으십시오!
ⓘ이 튜토리얼의 시작 부분에 모든 소스 코드가 포함 된 zip 파일이 포함되어 있으므로 모든 것을 복사하여 붙여 넣을 필요가 없습니다.
다운로드
먼저 약속 된 예제 코드에 대한 다운로드 링크가 있습니다.
소스 코드 다운로드
모든 예제 소스 코드를 다운로드하려면 여기를 클릭하십시오. MIT 라이센스에 따라 릴리스 했으므로 코드 위에 빌드하거나 자신의 프로젝트에서 자유롭게 사용할 수 있습니다.
빠른 시작
PHP 메일 기본
여러 수신자에게 실제로 들어가기 전에 먼저 기본 PHP 메일 기능을 간략하게 살펴 보겠습니다. 이미 고급 코드 사용자인 경우 이 섹션을 건너 뛰십시오.
기본 메일 발송
$to = "goodboy@doge.com"; $subject = "Hey Doge!"; $message = "Wow. Very message. Such test. Much words."; $sent = mail($to, $subject, $message); echo $sent ? "Mail send OK" : "Mail send ERROR" ;
그러나 PHP 메일 (TO, SUBJECT, MESSAGE, HEADERS, PARAMETERS)은 5 가지 매개 변수를 취하는 매우 간단한 기능입니다.
아래의 엑스트라 섹션에 공식 PHP 매뉴얼에 대한 링크를 남겨 두어야 합니다. 원하는 경우 추가 매개 변수를 확인할 수 있습니다.
여러 수신자
PHP 메일 기능으로 여러 수신자를 어떻게 정의합니까? 정답은 실제로 공식 참조 페이지에 있습니다. 그러나 이 섹션에서 조금 더 깊이 살펴 보도록 하겠습니다.
여러 수신자
첫눈에“email to”매개 변수는 한 명의 수신자 만 허용하는 것으로 보이지만 실제로는 RFC 2822 표준을 준수하는 문자열을 허용합니다. 의미, 우리는 여러 수신자를 던질 수 있습니다 :
// The easiest way to add multiple recipients, just separate the emails with a comma $to = "goodboy@doge.com, doggo@doge.com"; // Alternatively, you can also add the recipient's name $to = "Doge <goodboy@doge.com>, Doggo <doggo@doge.com>"; // The rest is pretty much the same $subject = "Hey Doge!"; $message = "Wow. Very message. Such test. Much words."; $sent = mail($to, $subject, $message); echo $sent ? "Mail send OK" : "Mail send ERROR" ;
CC 추가
이메일에 CC 수신자를 추가하는 것은 조금 까다롭기 때문에 사용자 정의 이메일 헤더를 정의해야 합니다.
// These are our "usual" mail parameters $to = "goodboy@doge.com, doggo@doge.com"; $subject = "Hey Doge!"; $message = "Wow. Very message. Such test. Much words."; // CC in the customer header $headers = [ 'MIME-Version: 1.0', 'Content-type: text/plain; charset=utf-8', 'From: hooman@doge.com', 'Cc: pupper@doge.com' ]; $headers = implode("\r\n", $headers); // Send the email $sent = mail($to, $subject, $message, $headers); echo $sent ? "Mail send OK" : "Mail send ERROR" ;
여러 CC 추가
짐작할 수 있듯이 여러 CC 수신자를 추가하는 것은 전자 메일 목록을 쉼표로 구분하여 정의하는 것과 거의 같습니다.
// These are our "usual" mail parameters $to = "goodboy@doge.com, doggo@doge.com"; $subject = "Hey Doge!"; $message = "Wow. Very message. Such test. Much words."; // CC in the customer header // Multiple CC recipients separated by comma $headers = [ 'MIME-Version: 1.0', 'Content-type: text/plain; charset=utf-8', 'From: hooman@doge.com', 'Cc: pupper@doge.com, woofer@doge.com' ]; $headers = implode("\r\n", $headers); // Send the email $sent = mail($to, $subject, $message, $headers); echo $sent ? "Mail send OK" : "Mail send ERROR" ;
숨은 참조 추가
마지막으로 추가 설명이 필요 없다고 생각합니다. 헤더에 다른 행을 추가하면 BCC 수신자를 이메일에 포함 시킬 수 있습니다.
// These are our "usual" mail parameters $to = "goodboy@doge.com, doggo@doge.com"; $subject = "Hey Doge!"; $message = "Wow. Very message. Such test. Much words."; // BCC in the customer header as well $headers = [ 'MIME-Version: 1.0', 'Content-type: text/plain; charset=utf-8', 'From: hooman@doge.com', 'Cc: pupper@doge.com, woofer@doge.com', 'Bcc: fluffer@doge.com, bork@doge.com' ]; $headers = implode("\r\n", $headers); // Send the email $sent = mail($to, $subject, $message, $headers); echo $sent ? "Mail send OK" : "Mail send ERROR" ;
EXTRA) 답장
눈치 채지 못한 경우를 대비하여 사용자 정의 헤더에서 "이메일 발신"및 "답장"필드를 설정할 수도 있습니다.
// These are our "usual" mail parameters $to = "goodboy@doge.com, doggo@doge.com"; $subject = "Hey Doge!"; $message = "Wow. Very message. Such test. Much words."; // Custom headers $headers = [ 'MIME-Version: 1.0', 'Content-type: text/plain; charset=utf-8', 'From: hooman@doge.com', 'Reply-To: reply@doge.com', 'Cc: pupper@doge.com, woofer@doge.com', 'Bcc: fluffer@doge.com, bork@doge.com' ]; $headers = implode("\r\n", $headers); // Send the email $sent = mail($to, $subject, $message, $headers); echo $sent ? "Mail send OK" : "Mail send ERROR" ;
유용한 비트
이 튜토리얼의 모든 코드에 대한 내용이며 여기에 유용한 추가 정보에 대한 작은 섹션이 있습니다.
요약
인포 그래픽 치트 시트
링크 및 참조
등록된 댓글이 없습니다.