Jump to content

Email attatchment


Peggy

Recommended Posts

So I'm trying to send a email from a form with an attachment (word doc) . Can anyone help?

here is the code that send s the email

 

<?php

 

$css_email = '

<style type="text/css">

div{

width:550px;

display:block:

}

.l_long_nopad{

float:left;

display:block;

width:140px;

text-align:right;

margin-right:15px;

}

p.form{

float:left;

clear:left;

display:block;

width:540px;

}

</style>

';

 

 

$to = '[email protected]';

 

$boundary = '-----=' . md5( uniqid ( rand() ) );

 

$message ='<html>

<head>'

.$css_email.

'</head>

<body>

<div>

'.$sentance.'

</div>

</body>

</html>';

 

 

 

 

$message .= "Content-Type: application/msword"; name=".$attachment."\n";

$message .= "Content-Transfer-Encoding: base64 \n";

$message .= "Content-Disposition: attachment; filename=".$attachment."\n\n";

 

$path = 'uplaods/'.$attachment;

$fp = fopen($path, 'r');

do //we loop until there is no data left

{

$data = fread($fp, 8192);

if (strlen($data) == 0) break;

$content .= $data;

} while (true);

$content_encode = chunk_split(base64_encode($content));

$message .= $content_encode . "\n";

$message .= "--" . $boundary . "\n";

 

$headers  = "From:".$email."\n";

$headers .= "MIME-Version: 1.0\n";

$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";

 

 

 

mail($to, $subject, $message, $headers);

 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/193008-email-attatchment/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.