Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sending mail with pdf attachment

1 view
Skip to first unread message

Merlin

unread,
Apr 17, 2003, 10:48:00 AM4/17/03
to php-g...@lists.php.net
Hi there,

I would like to send email with php mail function incuding a pdf attachment.
After playing around with it and several searches on google I am stuck. The
mail is delivered, and the attachment contains plain text (the message).

Maybe someone can give me a small hint. I guess it can't be that hard to
send an pdf attachment ??!!

Thanx,

Merlin

// send mail with attachment

function my_mail3($to,$subject,$message,$from){


$mailHeaders = "From: ".$from."\n"; // from
$mailHeaders .= "X-Mailer: PHP\n"; // mailer

$mailHeaders .= "Return-Path: <".$from.">\n"; // Return path for errors

$mailHeaders .= "MIME-Version: 1.0\r\n";
$mailHeaders .= "Content-Type: application/pdf; name=test.pdf;
Content-Disposition: attachment; Content-Transfer-Encoding:
quoted-printable\r\n";
#$headers .= "X-Attach my_file_path";

$body = $message;


if (mail($to, $subject, $body, $mailHeaders) ){
return true;
}
else{
return false;
};
}

Peter Pistorius

unread,
Apr 17, 2003, 10:50:01 AM4/17/03
to php-g...@lists.php.net
Normally you would have to write some sort of MIME message parser that would
encode the attachment in to your message but PEAR (Yeah!) has made this
wonderfully easy for us:

http://pear.sourceforge.net/manual/core.mail.mime.php

addAttachment()
Adds an attachment to the email. It takes five arguments:

a.. $file - Either a filename or the actual file data itself.

b.. $c_type - Content type of the file. Defaults to
application/octet-stream if not given.

c.. $name - The filename of the file. Defaults to blank if not given.

d.. $isfilename - Whether the $file argument is a filename or not. If
true, the file will be read in Defaults to true if not given.

e.. $encoding - Type of transfer encoding to use for the file data.
Defaults to base64 if not given. for text based files (eg. scripts/html etc)
this could be given as quoted-printable.

Regards,
Peter "Pod" Pistorius
(Poor, unemployed, student in South Africa)

pet...@podbox.co.za

Jason Wong

unread,
Apr 17, 2003, 10:54:36 AM4/17/03
to php-g...@lists.php.net
On Thursday 17 April 2003 22:48, Merlin wrote:

> I would like to send email with php mail function incuding a pdf
> attachment. After playing around with it and several searches on google I
> am stuck. The mail is delivered, and the attachment contains plain text
> (the message).
>
> Maybe someone can give me a small hint. I guess it can't be that hard to
> send an pdf attachment ??!!

archives > email attachment

--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
If at first you fricasee, fry, fry again.
*/

Peter Pistorius

unread,
Apr 17, 2003, 11:26:53 AM4/17/03
to php-g...@lists.php.net
Unfortunatly I have never used PEAR, but this is what it said in the
function reference under mail():

Email with attachments and special types of content can be sent using this
function. This is accomplished via MIME-encoding - for more information, see
this (http://http://www.zend.com/zend/spotlight/sendmimeemailpart1.php)
article or the PEAR mime class.


Merlin

unread,
Apr 17, 2003, 11:25:47 AM4/17/03
to php-g...@lists.php.net
Hello Peter,

I tryed the example in pear. Unfortunatelly one file seems missing.
mime.php:

SARATOGA:~ # ls /usr/local/lib/php/Mail/
RFC822.php sendmail.php smtp.php

Do I have to install a new version of pear? I remember that I have
previously send jpg images simply with php mail(), but cant find the code
anymore. Do I really need pear, and if so, do I have to upgrade? I am
running php 4.2.1

cheers,

merlin

"Peter Pistorius" <pet...@podbox.co.za> schrieb im Newsbeitrag
news:2003041714540...@pb1.pair.com...

Brian Paulson

unread,
Apr 17, 2003, 11:53:15 AM4/17/03
to Merlin, php-g...@lists.php.net
Here is the function I have been using works like a charm just set the
type to "multipart/mixed"


function sendmsg($to, $subject, $text, $from, $file, $type) {
$content = fread(fopen($file,"r"),filesize($file));
$content = chunk_split(base64_encode($content));
$uid = strtoupper(md5(uniqid(time())));
$name = basename($file);
$header = "From: $from\nReply-To: $from\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=$uid\n";
$header .= "--$uid\n";
$header .= "Content-Type: text/plain\n";
$header .= "Content-Transfer-Encoding: 8bit\n\n";
$header .= "$text\n";
$header .= "--$uid\n";
$header .= "Content-Type: $type; name=\"$name\"\n";
$header .= "Content-Transfer-Encoding: base64\n";
$header .= "Content-Disposition: attachment;
filename=\"$name\"\n\n";
$header .= "$content\n";
$header .= "--$uid--";
mail($to, $subject, "", $header);
return true;
}

Thank You
Brian Paulson
Sr. Web Developer
Email: Bpau...@Chieftain.com
Phone: 1-800-279-6397
Fax: 1-719-544-0264
URL: www.chieftain.com
-------------------------------------------


Hi there,

Thanx,

Merlin

function my_mail3($to,$subject,$message,$from){

$body = $message;


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Mike Jackson

unread,
Apr 17, 2003, 12:14:50 PM4/17/03
to php-g...@lists.php.net
ext Merlin (news....@web.de) wrote:
> Hello Peter,
>
> I tryed the example in pear. Unfortunatelly one file seems missing.
> mime.php:

Give the command:

pear install Mail_Mime

I just installed this same class last week :-) pear will fetch it
automatically over the network. If you're behind a firewall, make sure
that you have $http_proxy and $ftp_proxy set.

--
mike

Manuel Lemos

unread,
Apr 21, 2003, 4:59:07 AM4/21/03
to Merlin, php-g...@lists.php.net
Hello,

On 04/17/2003 11:48 AM, Merlin wrote:
> I would like to send email with php mail function incuding a pdf attachment.
> After playing around with it and several searches on google I am stuck. The
> mail is delivered, and the attachment contains plain text (the message).
>
> Maybe someone can give me a small hint. I guess it can't be that hard to
> send an pdf attachment ??!!

Try this class that lets you compose messages with attachments and more
very easily:

http://www.phpclasses.org/mimemessage


--

Regards,
Manuel Lemos

Mario Soto

unread,
Apr 22, 2003, 12:12:21 PM4/22/03
to Peter Pistorius, php general
Read the rfc2045. Rfc can be founded at rfc-editor.org (ftp://ftp.rfc-editor.org/in-notes/rfc2045.txt)

Mario Soto
mar...@amigo.net.gt
-.-.-.-

0 new messages