Re: how to send attachment with email in php? HELP plz.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Have a look at the message below extracted 
from http://www.php.net/manual/en/ref.mail.php
---------------------------------------------------
jdephix at hotmail dot com
02-Mar-2005 03:25
How to add multiple attachment to an email:

An email can be split into many parts separated by a
boundary followed by a Content-Type and a
Content-Disposition.

The boundary is initialized as follows:
<?php
$boundary = '-----=' . md5( uniqid ( rand() ) );
?>

You can attach a Word document if you specify:
<?php
$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:
<?php
$path = "whatever the path to the file is";
$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";
?>

Add the needed headers and send!
<?php
$headers  = "From: \"Me\"<me@xxxxxxxx>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;
boundary=\"$boundary\"";
mail('myAddress@xxxxxxxxxxx', 'Email with attachment
from PHP', $message, $headers);
?>

Finally, if you add an image and want it displayed in
your email, change the Content-Type from attachment to
inline:

<?php
$message .= "Content-Disposition: inline;
filename=\"$theFile\"\n\n";
?>

Enjoy!


--- Muhammad Sohail Khan <mr_sohail_khan@xxxxxxxxx>
escreveu:


---------------------------------
Hi Gurus....

Plz any body can help me in sending email with
attachment in php.

Plz Hurry Up......
Thnx in advance...

Khan







PHP Data object relational mapping generator -
http://www.meta-language.net/

  
    
---------------------------------
  YAHOO! GROUPS LINKS

  
    Visit your group "php-objects" on the web.
   
    To unsubscribe from this group, send an email to:
 php-objects-unsubscribe@xxxxxxxxxxxxxxx
   
    Your use of Yahoo! Groups is subject to the Yahoo!
Terms of Service.

  
---------------------------------





	



	
		
_______________________________________________________ 
Novo Yahoo! Messenger com voz: ligações, Yahoo! Avatars, novos emoticons e muito mais. Instale agora! 
www.yahoo.com.br/messenger/


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~-> 

PHP Data object relational mapping generator - http://www.meta-language.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux