我正在尝试创建一个电子邮件表单,其中某些地址是固定的,而其他地址是可变的,取自文本字段。
是否可以以这种方式连接CC头?
$headers .= "CC: fixed@email.com, fixed@email2.com\r\n";
$headers .= "CC: ".$additional_emails."\r\n";
答案 0 :(得分:2)
是的,但是你做错了。
$headers .= "CC: fixed@email.com, fixed@email2.com";
$headers .= ", ". $additional_emails;
$headers .= "\r\n";
$additional_emails
以逗号分隔。检查$additional_emails
是否有值时也值得。
$headers .= "CC: fixed@email.com, fixed@email2.com";
if( strlen($additional_emails) > 0 ) {
$headers .= ", ". $additional_emails;
}
$headers .= "\r\n";
如果$additional_emails
是数组,则可以使用implode()
。
$headers .= "CC: fixed@email.com, fixed@email2.com";
if( count($additional_emails) > 0 ) {
$headers .= ", ". implode(",", $additional_emails);
}
$headers .= "\r\n";
答案 1 :(得分:0)
Tray it
$to = 'abc@gmail.com';
$subject = "Hii";
$message = "";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <abs@gmail.com>' . "\r\n";
$headers .= 'Cc: xyz@gmail.com,xyz@gmail.com,'.$email. "\r\n";
$mail=mail($to,$subject,$message,$headers);