带附件的电子邮件转到垃圾邮件文件夹 - VPS服务器

时间:2013-08-16 11:00:32

标签: php html-email

我正在尝试解决问题。带有附件的电子邮件到垃圾邮件文件夹。以前我遇到过类似的问题&那些是HTML电子邮件。但这里有附件。如果我没有添加标题中的“发件人”电子邮件将进入收件箱(username@vps.mydomain.com)。实际上我想要改变这个发件人的电子邮件,以便它不会去垃圾邮件。我已设法更改标题中的“发件人”,但仍然转到垃圾邮件。

此外,我尝试了“-f”概念,仍然是垃圾邮件。

这是标题&带附件的消息

$header .= "MIME-Version: 1.0\r\n";  
//$header .= 'From: Move <info@ccc.com>' . "\r\n";  
//$header .= "Reply-To: ".$replyto."\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$message = "This is a multi-part message in MIME format.\r\n\r\n";
$message .= "--".$uid."\r\n";
$message .= "Content-type:text/html; charset=iso-8859-1\r\n";  
$message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$message .= $emailtext."\r\n\r\n";
$message .= "--".$uid."\r\n";
$message .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";    
$message .= $content."\r\n\r\n";
$message .= "--".$uid."--";   

if (mail($email, $subject, $message, $header, "-finfo@ccc.com")) {

1 个答案:

答案 0 :(得分:0)

编辑#2 :( PDF附件)

您需要输入$_POST变量,但如果您按原样尝试,包括您要发送的PDF文件,则会自行运行。将代码中file.pdf的所有实例更改为您要附加的文件名,以及您的电子邮件地址。 (的检测过

<?php
$sendto = "email@example.com";
$message = "Message here\r\n Hello, this is a test!!";

$filename = "file.pdf";
$handle = fopen($filename, 'rb');
$contents = fread($handle,filesize($filename));
fclose($handle);
$encoded = chunk_split(base64_encode($contents));

$seperator = md5(uniqid(time()));
$from = '"First Last" <username@domain.com>';
$header = '';
$header .= "From: $from\r\n";
$header .= "MIME-Version: 1.0\r\nContent-Type:"." multipart/mixed; boundary=\"$seperator\";\r\n";


$body.= "--$seperator\r\n";
$body.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$body.= "Content-Transfer-Encoding: 7bit\r\n\n";
$body.= $message."\r\n\n";

$body.= "--$seperator\r\n";
$body.= "Content-Type: application/pdf; name=\"file.pdf\"\r\n";
$body.= "Content-Transfer-Encoding: base64\r\n";
$body.= "Content-Disposition: attachment; filename=\"file.pdf\"\r\n\n";
$body.= $encoded."\r\n";
$body.= "--$seperator--\r\n";

mail($sendto,$subject, $body, $header);
?>