0

I'm trying to fix a issue. where email with attachments going to Spam Folder. Previously i came across similar issues & those are HTML email.but here its with attachment. if i did not add the "From" in the header email is coming to inbox (username@vps.mydomain.com). Actually i'm tying to change this sender email so that it wont go to SPAM. i have managed to change the "From" in header but still it goes to SPAM.

Also i tried "-f" concept, still it goes to SPAM.

Here is the headers & Message with attachment

$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")) {
Parthi04
  • 1,121
  • 4
  • 21
  • 39
  • Maybe, this also depends on the subject/title and content. – huysentruitw Aug 16 '13 at 11:10
  • @WouterHuysentruit I tied changing the Message(Paintext) & Subject also. Still it goes to spam – Parthi04 Aug 16 '13 at 11:17
  • The reason is, you're inserting header information into your `message`. Change all of your `$message` to `$header` while concatenating properly, then add `$message=""` and keep going. – Funk Forty Niner Aug 16 '13 at 11:29
  • @Fred. Yes i noticed that i tried a new sample given here http://stackoverflow.com/questions/9519588/send-php-html-mail-with-attachments – Parthi04 Aug 16 '13 at 11:32
  • @Fred its also going to SPAM Folder. in that example they have added those content types to header which was wrong in mine. – Parthi04 Aug 16 '13 at 11:33
  • @Parthi04 it's going to Spam because of that. Have a look at my example below. – Funk Forty Niner Aug 16 '13 at 11:37
  • @Fred Here my scenario is I have to send the HTML email with attachments. i tried few examples which looks similar to your code below. HTML email is fine. once i think about the attachments.facing this issue. – Parthi04 Aug 16 '13 at 11:41
  • @Parthi04 I think I may have something for you, give me a few minutes. – Funk Forty Niner Aug 16 '13 at 11:43
  • @Fred Example in this link http://stackoverflow.com/questions/9519588/send-php-html-mail-with-attachments. if i comment the From & reply to header. email is coming to inbox. once i un comment that then it goes to SPAM – Parthi04 Aug 16 '13 at 11:44
  • @Parthi04 Are you trying to send ONE attachment or many at a time? – Funk Forty Niner Aug 16 '13 at 11:49
  • It is coming to spam because of your VPS host. Modern email systems use global service for IP authorization and your IP does not seem to be authorized, why? Because 97% of emails are spam and so everyone could setup their SMTP service and bomb email services. So your way is to use some paid certificated SMTP service :] + attachment = 100% spam. – Wiggler Jtag Aug 16 '13 at 11:50
  • @Parthi04 Found a few articles/answers that could be of help. I Google'd "mail goes to SPAM VPS" in case you wish to further your research. http://stackoverflow.com/a/8530251/1415724 and http://forums.deftechgroup.com/showthread.php?t=3685 <= links in there too. And http://forums.cpanel.net/f43/mail-marked-spam-tried-everything-157225.html and http://forums.zpanelcp.com/thread-4606-post-38890.html#pid38890 I wish you well :) Cheers (*Peace*) – Funk Forty Niner Aug 16 '13 at 12:17

1 Answers1

0

EDIT #2: (PDF attachment)

You will need to enter your $_POST variables, but if you try this as is, including the PDF file you wish to send, will run on its own. Change all instances of file.pdf in the code to the file name you wish to attach, as well as your Email address. (TESTED)

<?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);
?> 
Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • form VPS host - its coming to inbox without attachement but attached PDF is not coming in email. – Parthi04 Aug 16 '13 at 12:03
  • @Parthi04 Ah so it's a PDF then, that could make a difference. I have another script for that. Let you know in a few minutes. Will clear my answer with new code. – Funk Forty Niner Aug 16 '13 at 12:06
  • @Parthi04 See my Edit #2. Tested – Funk Forty Niner Aug 16 '13 at 12:08
  • i think VPS Host is making these issue. i tried few sample code.none of them are working. Everything goes to SPAM – Parthi04 Aug 16 '13 at 12:11
  • @Parthi04 I tend to think so too. Sorry my code didn't work. I can delete my answer if you wish. – Funk Forty Niner Aug 16 '13 at 12:15
  • Thanks for trying it along with me. Don't delete it. if someone face same issue & if this answer solves it, we might consider this answer as reference. – Parthi04 Aug 16 '13 at 12:20
  • @Parthi04 You're very much welcome. I will do as you wish then. I hope you resolve your issue, cheers! – Funk Forty Niner Aug 16 '13 at 12:21
  • @Parthi04 Cheers and have a look at the links I included in a comment in your question. (*Peace*) http://stackoverflow.com/questions/18271775/email-with-attachments-going-to-spam-folder-vps-server/18272454?noredirect=1#comment26802228_18271775 – Funk Forty Niner Aug 16 '13 at 12:23