$array = array('abc@gmail.com','xyz@gmail.com','sdf@gmail.com','wrd@gmail.com');
上面的代码,我手动输入了电子邮件。如何在现场使用用户输入的电子邮件?
我是说, 我有<input type="text" name="email[]">
字段。无论用户在此字段中输入批量电子邮件,我都必须将该电子邮件发送到数组,如下面的代码
$email=$_POST['email'];//emails comes from user input
$array = array($email);// store in array
$arrlength = count($array);// count how may emails are in the field
$subject=$_POST['subject'];
$mailbody=$_POST['mailbody'];
send($array,$arrlength, $subject, $mailbody);//It will send the value to mail page
答案 0 :(得分:3)
HTML:
<input type="text" name="email[]">
PHP:
你需要的是explode
。但是你需要从用户那里获得逗号分隔的电子邮件。
$emails=explode(",",$_POST['email']);//emails comes from user input
$arrlength = count($emails);// count how may emails are in the field
$subject=$_POST['subject'];
$mailbody=$_POST['mailbody'];
send($emails,$arrlength, $subject, $mailbody);