note 50876 rejected from ref.mail by nlopess
| From: | nlopess@php.net | Date: | Sat, 12 Mar 2005 20:03:20 +0000 |
| Subject: | note 50876 rejected from ref.mail by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-86332@lists.php.net to get a copy of this message | ||
Note Submitter: kahwinlee2000 at yahoo dot com dot cn
----
May I know wat is the problem in my code ???? I 'm totally a beginner in PHP..
<?php
$boundary = '-----=' . md5( uniqid ( rand() ) );
?>
You can attach a Word document if you specify:
<?php
$theFile = "monk4.jpg";
$message ="hi\n";
$message .= "Content-Type: application/msword; name= my attachment \n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment; filename=\"$theFile\"\n\n";
?>
When adding a file you must open it and read it with fopen and add the content to the
message: <br><br><br>
<?php
$content = "";
$path = "c:\monk4.jpg";
$fp = fopen($path, 'r');
do
{
$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";
?>
Add the needed headers and send! <br><br><br>
<?php
/*
$headers = "From: reliC\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
*/
?>
Finally, if you add an image and want it displayed in your email, change the Content-Type from
attachment to inline:<br><br><br><br>
<?php
$message .= "Content-Disposition: inline; filename=\"$theFile\"\n\n";
mail("smartcare@smartcare.com", "test SMTP with Attachment", $message);
?>