Welcome to WebmasterWorld Guest from 54.226.246.160

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Attaching HTML files to emails

     

dougmcc1

8:58 pm on Oct 4, 2009 (gmt 0)

10+ Year Member



I'm using the following php code to try to attach .html files to email using php but it's not attaching the file:

$recipient_email="webmaster@domain.com";
$subject = "Test email";
$mail_headers= "From: Me <me@mydomain.com>\r\n";
$mail_boundary = md5(uniqid(time()));
$mail_headers .= "MIME-Version: 1.0\r\n";
$mail_headers .= "Content-type: multipart/mixed;boundary=\"$mail_boundary \"";
$mail_headers .= "\r\n\r\n";
$mail_headers .= "This is a multi-part message in MIME format.";
$mail_headers .= "\r\n\r\n";
$userfile = "/home/account_name/public_html/test.html";
$fp = fopen($userfile, "r");
$file = fread($fp, filesize($userfile));
$file = chunk_split(base64_encode($file));
$mail_body = "--$mail_boundary\n";
$mail_body .= "Content-type: text/plain; charset=euc-kr\r\n";
$mail_body .= "Content-transfer-encoding: 8bit\r\n\r\n";
$mail_body .= " Here goes the project file.\r\n";
$mail_body .= "--$mail_boundary\r\n";
$filename = basename($userfile);
$mail_body .= "Content-type: text/html; name=$filename\r\n";
$mail_body .= "Content-transfer-encoding:base64\r\n\r\n";
$mail_body .= $file. "\r\n\r\n";
$mail_body .= " --$mail_boundary--";
$send_check2 = mail($recipient_email,$subject,$mail_body,$mail_headers);
if ($send_check2) {
echo "<p>The email has been sent.</p>";
}

The email is being sent out but there is no attachment. What am I doing wrong?

Also, it shows this output in the email message:
This is a multi-part message in MIME format.

--435a053fc841a34f1f24d497c55ef92b

Content-type: text/plain; charset=euc-kr
Content-transfer-encoding: 8bit

Here goes the project file.

--435a053fc841a34f1f24d497c55ef92b
Content-type: text/html; name=test.html
Content-transfer-encoding:base64

--435a053fc841a34f1f24d497c55ef92b--

dreamcatcher

8:44 am on Oct 5, 2009 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Google for PHPMailer. Its easy to use and will solve all your mail problems.

dc

dougmcc1

5:08 am on Oct 6, 2009 (gmt 0)

10+ Year Member



Thanks! I'll look into it.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month