PHP Mail, campo CC
Como posso incluir um campo CC nesta função?
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: text/html; charset=iso-8859-1\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
if (mail($mailto, $subject, "", $header)) {
echo "OK"; // or use booleans here
} else {
echo "ERROR!";
}
}
18
Author: Shawn Chin, 2010-08-27
3 answers
Adicione isto enquanto declara os cabeçalhos:
$headers .= 'Cc: [email protected]' . "\r\n";
52
Author: Otar, 2010-08-27 07:24:11
Adicionar $header .= "CC: ".$cc."\r\n";
depois da linha Reply-To
.
15
Author: Select0r, 2010-08-27 07:24:27
Por favor, não construas os teus próprios e-mails mimos. Use algo como PHPMailer em vez disso. Muito mais fácil de usar e menos frágil. Adicionar um CC com isso é tão simples como:
$mail = new PHPMailer();
$mail->AddCC('[email protected]');
5
Author: Marc B, 2017-09-06 08:46:56