我有这个 PHP 函数可以向 MySQL 数据库中的地址发送电子邮件:
require_once "/usr/local/lib/php/Mail.php";
$from = $email_from;
$to = $email_to;
$subject = $email_subject;
$body = $email_body;
$host = "mail.domain.co.uk";
$username = "sending@domain.co.uk";
$password = "*********";
$headers = array ('From' => $from,
'To' => $to,
'Cc' => $cc,
'Subject' => $subject,
'Content-type' => 'text/html');
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$rec = $to.', '.$cc;
$mail = $smtp->send($rec, $headers, $body);
每个电子邮件地址都用逗号分隔,例如:
mail@domain.com,mail2@domain2.co.uk
我试过使用:
if(filter_var($email_to, FILTER_VALIDATE_EMAIL))
但这仅适用于一个电子邮件地址,如何验证多个用逗号分隔的地址?
如何验证$to
and中的逗号分隔值$cc
?