
- You are not logged in. | Login
January 16, 2007 2:24 pm
- napkdd1
- Member


how to send email with attachments or in the html format
Hi, all
Caould you olease tell me how to send email with attachments or in the html format?
if possible without sockets' using. Can i do this using mail() function having added to the header smth like multipart/mixed, and then in code attach ?
January 16, 2007 2:25 pm
- steven9x
- Member


Re: how to send email with attachments or in the html format
look here http://pear.php.net/package/Mail
January 16, 2007 2:28 pm
- phppat
- Member


Re: how to send email with attachments or in the html format
<?php
function send_mail($to, $thm, $html, $path)
{
$fp = fopen($path,"r");
if (!$fp)
{
print "File $path can't be read";
exit();
}
$file = fread($fp, filesize($path));
fclose($fp);
$path = substr($path,12);
$boundary = "--".md5(uniqid(time())); // generate the boundary
$headers = "MIME-Version: 1.0\n";
$headers .="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
$multipart = "--$boundary\n";
//$kod='windows-1251';
$kod='koi8-r';
$multipart .= "Content-Type: text/html; charset=$kod\n";
$multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n";
$multipart .= "$html\n\n";
$message_part = "";
$message_part .= "Content-Type: application/octet-stream";
$message_part .= "; file_name = \"$path\"\n";
$message_part .= "Content-Transfer-Encoding: base64\n";
$message_part .= "Content-Disposition: attachment; filename = \"".$path."\"\n\n";
$message_part .= chunk_split(base64_encode($file))."\n";
$multipart .= "--$boundary\n".$message_part."--$boundary--\n";
if(!mail($to, $thm, $multipart, $headers))
{
echo "Failed to send the message";
exit();
} else{echo "Milk";};
}
>
Last edited by phppat (January 16, 2007 2:28 pm)
PHP monster
January 16, 2007 2:41 pm
- napkdd1
- Member


Re: how to send email with attachments or in the html format
phppat, it's great. Please give the link where i can read about MIME headers. Your code has Content-Disposition: attachment; line, if I want to send the html document background image there should be another location. am i right?
Last edited by napkdd1 (January 16, 2007 2:42 pm)
January 16, 2007 2:43 pm
- phppat
- Member


Re: how to send email with attachments or in the html format
You can find it in google
You are right about location
PHP monster
January 16, 2007 2:46 pm
- napkdd1
- Member


Re: how to send email with attachments or in the html format
I understood how to insert the image to the letter: content-disposition: inline; but when I send the letter
<html>
<head><style>
h2 {font-weight: normal; color: navy; font-size: 20pt; font-family: georgia}
</style></head>
<body bgcolor=gold background=sf4.gif><h2>This is a test</h2></body></html>it doesn't become a background. It is just attached at the end of the message.
How can I make a background??? Who knows??
Last edited by napkdd1 (January 16, 2007 2:47 pm)


