Tất cả các câu trả lời là rất lớn. Dưới đây là một trường hợp ví dụ sử dụng cho nhiều địa chỉ add: Khả năng thêm bao nhiêu email mà bạn muốn theo yêu cầu với một mẫu web:
See it in action with jsfiddle here (ngoại trừ bộ vi xử lý php)
### Send unlimited email with a web form
# Form for continuously adding e-mails:
<button type="button" onclick="emailNext();">Click to Add Another Email.</button>
<div id="addEmail"></div>
<button type="submit">Send All Emails</button>
# Script function:
<script>
function emailNext() {
var nextEmail, inside_where;
nextEmail = document.createElement('input');
nextEmail.type = 'text';
nextEmail.name = 'emails[]';
nextEmail.className = 'class_for_styling';
nextEmail.style.display = 'block';
nextEmail.placeholder = 'Enter E-mail Here';
inside_where = document.getElementById('addEmail');
inside_where.appendChild(nextEmail);
return false;
}
</script>
# PHP Data Processor:
<?php
// ...
// Add the rest of your $mailer here...
if ($_POST[emails]){
foreach ($_POST[emails] AS $postEmail){
if ($postEmail){$mailer->AddAddress($postEmail);}
}
}
?>
Vì vậy, những gì nó về cơ bản là tạo ra một hộp văn bản đầu vào mới trên mỗi nhấp chuột với tên "email []".
Biểu tượng [] được thêm vào cuối sẽ biến thành mảng khi được đăng.
Sau đó chúng tôi đi qua từng phần tử của mảng với "foreach" trên PHP phụ thêm:
$mailer->AddAddress($postEmail);
PHPMailer bây giờ có thể (tháng 5 năm 2015) xử lý các loại chuỗi địa chỉ thông qua một chức năng phân tích cú pháp. Xem [câu trả lời này] (http://stackoverflow.com/a/30377848/333340) – Synchro