So i was trying to send MIME email with the mail function instead of using sockets. But i noticed sumtin strange that wont let me send proper emails.
this is my code:
<?php
if (!isset($_POST['submit']) or $_POST['submit']!="submit") {
?>
<html>
<body>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data">
<textarea name="msg" cols="75" rows="20"></textarea><br />
<input type="file" name="filename">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?php
} else {
function sendmsg($to, $subject, $text, $from, $file, $type, $name) {
$fp = fopen($file,"rb");
$content = fread($fp,filesize($file));
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$header = Array();
$header[] = "From: $from\r\nReply-To: $from\r\n";
$header[] = "Return-Path: [email]postmaster@ndngangstaproductionz.com[/email]\r\n";
$header[] = "MIME-Version: 1.0\r\n";
$header[] = "Content-Type: multipart/mixed;\r\n";
$header[] = "\tboundary=\"$uid\";\r\n";
$header[] = "Content-Transfer-Encoding: 7bit\r\n";
$header[] = "\r\n";
$header[] = "This is a MIME encoded Message.\r\n";
$header[] = "\r\n";
$header[] = "--$uid\r\n";
$header[] = "Content-Type: text/plain; charset=us-ascii\r\n";
$header[] = "Content-Transfer-Encoding: 7bit\r\n";
$header[] = "\r\n";
$header[] = "$text\r\n";
$header[] = "\r\n";
$header[] = "--$uid\r\n";
//
$header[] = "Content-Type: $type; name=\"$name\"\r\n";
$header[] = "Content-Transfer-Encoding: base64\r\n";
$header[] = "Content-Disposition: attachment; filename=\"$name\"\r\n";
$header[] = "\r\n";
$header[] = "$content\r\n"."\r\n";
$header[] = "\r\n--$uid--\r\n";
echo '<pre>'.join("", $header)."\r\n</pre>";
mail($to, $subject, "", join("", $header)."\r\n");
return true;
}
if (!sendmsg("postmaster@ndngangstaproductionz.com", "Attachment TEst", $_POST['msg'], "attacher@home", $_FILES['filename']['tmp_name'], $_FILES['filename']['type'], $_FILES['filename']['name'])) die("did not work");
}
?>
For this code to work properly, there shudd be a blank line right after each 'Content-Transfer-Encoding:' header and right before the 'boundary' seperators. When i echo my header, everything is fine, but once i pass it thru the mail function, the blank lines are ripped off.
Is der a way to avoid this without using anything other than mail()?. If you don't completely get my question, I will glad to explain it more.
thnx