我有这个小小的磕磕碰碰...... 我试图发送密件抄送副本但是当我增加页眉数量时,附加文件将作为图像代码发送。
这是我的代码:
$to="name@extension.com";
$subject="Petición de financiamiento";
$from = stripslashes($_POST['nombre'])."<".stripslashes($_POST['correo']).">";
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$message="Petición de financiamiento\r\n";
$message .="\r\n";
$message .= "Nombre: ".$_POST["nombre"]."\r\n";
$message .= "Correo: ".$_POST["correo"]."\r\n";
$message .= "Teléfono: ".$_POST["telef"]."\r\n";
$message .="\r\n";
$message .="\r\n";
$message .= $_POST["mensaje"];
$message .="\r\n";
$message .="\r\n";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
foreach($_FILES as $userfile){
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
if (file_exists($tmp_name)){
if(is_uploaded_file($tmp_name)){
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
}
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
$message.="--{$mime_boundary}--\n";
$message.="--{$mime_boundary}--\n";
if (@mail($to, $subject, $message, $headers))
echo "Mensaje enviado";
else
echo "No se pudo enviar";
任何想法如何添加BCC,请提前感谢您的帮助。
答案 0 :(得分:0)
在内容类型行
之后添加$headers .= "Bcc: $emailadress\r\n";
这应该可行。我猜。
答案 1 :(得分:0)
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
在标题上添加此行
$headers.= "Bcc: email@example.com" . "\r\n";
答案 2 :(得分:0)
[编辑以适应真实的&#39;解决方案Sam Ram San自己发现了]
管理标题(包括密送)的一种不错,清晰且可扩展的方式:
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: $from";
$headers[] = "Bcc: $bcc_address1,$bcc_address2,$bcc_address3";
// and so on...
mail($to, $subject, $email, implode("\r\n", $headers));
使用此功能可以避免在标题字段名称前面添加不需要的空格(&#34;密送&#34; - &gt;正确。&#34;密件抄送&#34; - &gt;不正确)
已编辑:作为发送电子邮件时的一般规则,应使用逗号(&#34;,&#34;)分隔多个地址(来自,cc,bcc,cco ...字段)。即:$ bcc =&#34; john @ doe.com,james @ doe.org,lucy @ doe.com&#34;
答案 3 :(得分:0)
我需要做的就是在:
上使用csv$to="name@extension.com,mail2@bla.com";
谢谢你们。