[英]How to send to multiple email recipients using php
I have problem receiving notification using bunch of email recipients, the only email received notification is the last email on the line (email5@mysite.com) im been wondering why and what's the problem? 我在使用一堆电子邮件收件人接收通知时遇到问题,唯一收到的电子邮件通知是该行上的最后一封电子邮件(email5@mysite.com),我一直在想为什么以及这是什么问题? Any help will be appreaciated. 任何帮助将不胜感激。
<?php
class QIF_Email {
function send_email(){
$to= "email1@mysite.com,email2@mysite.com,email3@mysite.com,email4@mysite.com,email5@mysite.com,";
$subject="Inquiry";
$header="mysite.com - Inquiry";
$message="Date: ".$_POST['date']." \r\n";
$message.="Name: ".$_POST['name']." \r\n";
$message.="Company Name: ".$_POST['company_name']." \r\n";
$message.="Contact: ".$_POST['contact']." \r\n";
$message.="Address: ".$_POST['address']." \r\n";
$message.="City: ".$_POST['city']." \r\n";
$message.="State: ".$_POST['state']." \r\n";
$message.="Zip Code: ".$_POST['zip_code']." \r\n";
$message.="Telephone / Fax: ".$_POST['telephone']." \r\n";
$message.="Email Address: ".$_POST['email_address']." \r\n";
$message.="Comments: ".$_POST['comments']." \r\n";
$sentmail = mail($to,$subject,$message,$header);
}
}
$qif = new QIF_Email;
$qif->send_email();
?>
Store your recipients as an array and send the email to each one 将收件人存储为数组,然后将电子邮件发送给每个收件人
class QIF_Email {
function send_email($to){
$subject="Inquiry";
$header="mysite.com - Inquiry";
$message="Date: ".$_POST['date']." \r\n";
$message.="Name: ".$_POST['name']." \r\n";
$message.="Company Name: ".$_POST['company_name']." \r\n";
$message.="Contact: ".$_POST['contact']." \r\n";
$message.="Address: ".$_POST['address']." \r\n";
$message.="City: ".$_POST['city']." \r\n";
$message.="State: ".$_POST['state']." \r\n";
$message.="Zip Code: ".$_POST['zip_code']." \r\n";
$message.="Telephone / Fax: ".$_POST['telephone']." \r\n";
$message.="Email Address: ".$_POST['email_address']." \r\n";
$message.="Comments: ".$_POST['comments']." \r\n";
$sentmail = mail($to,$subject,$message,$header);
}
}
$to[] = "email1@mysite.com";
$to[] = "email2@mysite.com";
for($i = 0; $i < count($to); $i++){
$qif = new QIF_Email;
$qif->send_email($to[$i]);
}
Not best practice but it should do the job 不是最佳做法,但应该可以完成工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.