homepage Welcome to WebmasterWorld Guest from 54.163.72.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Attaching HTML files to emails
dougmcc1




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

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




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

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

dc

dougmcc1




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

Thanks! I'll look into it.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved