Sending email w/ attachments

Sending email w/ attachments

am 11.08.2009 03:49:09 von Skip Evans

Hey all,

Trying to send emails with attachments, first try at this. And
am trying to adapt sample code I found here:

http://www.webcheatsheet.com/PHP/send_email_text_html_attach ment.php

Trying this:

($data contains the contents of the file; I've verified this)

$hash = md5(date('r', time()));
$attachment = chunk_split(base64_encode($data));
$body_attachment = "--PHP-mixed-$hash--\n" .
"Content-Type: application/octet-stream; name=\"$filename\"\r\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: attachment\n".
$attachment . "\n" .
"--PHP-mixed-$hash--\n";

I then append $attachment this to the end of the email body
and send it on. I've verified it is reading the file properly,
in this test case it is a place text file. But I've tried a
PDF and that did not work as well.

What happens is the email comes through and shows an
attachment paper clip icon in Thunderbird, but when the email
is clicked on the icon disappears and the email is empty, even
the body is not there and no attachment either.

A final question I have is does the content-type value need to
change for text files, Word Docs, PDFs, Excel files, etc, or
is there one type that can handle any file type?

Any help would be great. I'm rather stuck and floundering here.

Thanks,
Skip

--
====================================
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
-- Kurt Vonnegut

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

Re: Sending email w/ attachments

am 11.08.2009 03:55:02 von Phpster

On Mon, Aug 10, 2009 at 9:49 PM, Skip Evans wrote:
> Hey all,
>
> Trying to send emails with attachments, first try at this. And am trying =
to
> adapt sample code I found here:
>
> http://www.webcheatsheet.com/PHP/send_email_text_html_attach ment.php
>
> Trying this:
>
> ($data contains the contents of the file; I've verified this)
>
> $hash =3D md5(date('r', time()));
> $attachment =3D chunk_split(base64_encode($data));
> $body_attachment =3D "--PHP-mixed-$hash--\n" .
> "Content-Type: application/octet-stream; name=3D\"$filename\"\r\n" .
> "Content-Transfer-Encoding: base64\n" .
> "Content-Disposition: attachment\n".
> $attachment . "\n" .
> "--PHP-mixed-$hash--\n";
>
> I then append $attachment this to the end of the email body and send it o=
n.
> I've verified it is reading the file properly, in this test case it is a
> place text file. But I've tried a PDF and that did not work as well.
>
> What happens is the email comes through and shows an attachment paper cli=
p
> icon in Thunderbird, but when the email is clicked on the icon disappears
> and the email is empty, even the body is not there and no attachment eith=
er.
>
> A final question I have is does the content-type value need to change for
> text files, Word Docs, PDFs, Excel files, etc, or is there one type that =
can
> handle any file type?
>
> Any help would be great. I'm rather stuck and floundering here.
>
> Thanks,
> Skip
>
> --
> ==================== =====
============
> Skip Evans
> Big Sky Penguin, LLC
> 503 S Baldwin St, #1
> Madison WI 53703
> 608.250.2720
> http://bigskypenguin.com
> ------------------------------------
> Those of you who believe in
> telekinesis, raise my hand.
> =A0-- Kurt Vonnegut
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Use PHPMailer or one of the other classes available...makes life
sooooo much easier

--=20

Bastien

Cat, the other other white meat

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

Re: Sending email w/ attachments

am 11.08.2009 04:13:13 von Adam Randall

Funny, I just had to figure out today how to nicely do HTML e-mails. I
ended up using PEAR:Mail_mime, and it worked pretty well. It will also
work for your attachments. I believe that PHP itself recommends it on
their mail() function reference page.

Adam.

On Mon, Aug 10, 2009 at 6:49 PM, Skip Evans wrote:
> Hey all,
>
> Trying to send emails with attachments, first try at this. And am trying =
to
> adapt sample code I found here:
>
> http://www.webcheatsheet.com/PHP/send_email_text_html_attach ment.php
>
> Trying this:
>
> ($data contains the contents of the file; I've verified this)
>
> $hash =3D md5(date('r', time()));
> $attachment =3D chunk_split(base64_encode($data));
> $body_attachment =3D "--PHP-mixed-$hash--\n" .
> "Content-Type: application/octet-stream; name=3D\"$filename\"\r\n" .
> "Content-Transfer-Encoding: base64\n" .
> "Content-Disposition: attachment\n".
> $attachment . "\n" .
> "--PHP-mixed-$hash--\n";
>
> I then append $attachment this to the end of the email body and send it o=
n.
> I've verified it is reading the file properly, in this test case it is a
> place text file. But I've tried a PDF and that did not work as well.
>
> What happens is the email comes through and shows an attachment paper cli=
p
> icon in Thunderbird, but when the email is clicked on the icon disappears
> and the email is empty, even the body is not there and no attachment eith=
er.
>
> A final question I have is does the content-type value need to change for
> text files, Word Docs, PDFs, Excel files, etc, or is there one type that =
can
> handle any file type?
>
> Any help would be great. I'm rather stuck and floundering here.
>
> Thanks,
> Skip
>
> --
> ==================== =====
============
> Skip Evans
> Big Sky Penguin, LLC
> 503 S Baldwin St, #1
> Madison WI 53703
> 608.250.2720
> http://bigskypenguin.com
> ------------------------------------
> Those of you who believe in
> telekinesis, raise my hand.
>  -- Kurt Vonnegut
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--=20
Adam Randall
http://www.xaren.net
AIM: blitz574

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

Re: Sending email w/ attachments

am 11.08.2009 05:22:51 von Skip Evans

Bastien Koert wrote:
>
> Use PHPMailer or one of the other classes available...makes life
> sooooo much easier
>


Kick Ass!!!


Yes! Wow! Was that a breeze! That class rocks!

Thanks tons, Bastien!

I have to admit when I first saw your reply I thought, "Oh,
man, another class to learn? But I know this is so close to
working."

I look at the sample and thought, "This looks easy," and had
it working in no time.

Big thanks again!

Attachments were a big deal here and this makes it a breeze,
AND it looks like multiple attachments would be no problem?

Very cool!

Skip

--
====================================
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
-- Kurt Vonnegut

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

Re: Sending email w/ attachments

am 11.08.2009 10:23:29 von Devendra Jadhav

--000e0cd145f0d484f50470d96ad8
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Check out this link http://www.learnphp-tutorial.com/Email.cfm

On Tue, Aug 11, 2009 at 8:52 AM, Skip Evans wrote:

> Bastien Koert wrote:
>
>>
>> Use PHPMailer or one of the other classes available...makes life
>> sooooo much easier
>>
>>
>
> Kick Ass!!!
>

>
> Yes! Wow! Was that a breeze! That class rocks!
>
> Thanks tons, Bastien!
>
> I have to admit when I first saw your reply I thought, "Oh, man, another
> class to learn? But I know this is so close to working."
>
> I look at the sample and thought, "This looks easy," and had it working in
> no time.
>
> Big thanks again!
>
> Attachments were a big deal here and this makes it a breeze, AND it looks
> like multiple attachments would be no problem?
>
> Very cool!
>
>
> Skip
>
> --
> ====================================
> Skip Evans
> Big Sky Penguin, LLC
> 503 S Baldwin St, #1
> Madison WI 53703
> 608.250.2720
> http://bigskypenguin.com
> ------------------------------------
> Those of you who believe in
> telekinesis, raise my hand.
> -- Kurt Vonnegut
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
Devendra Jadhav

--000e0cd145f0d484f50470d96ad8--

Re: Sending email w/ attachments

am 11.08.2009 12:21:19 von Richard Heyes

Hi,

> Very cool!

I'll take that as a compliment... :-)

--
Richard Heyes
HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)

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

Re: Sending email w/ attachments

am 11.08.2009 12:52:58 von Phpster

On Aug 10, 2009, at 11:22 PM, Skip Evans wrote:

> Bastien Koert wrote:
>> Use PHPMailer or one of the other classes available...makes life
>> sooooo much easier
>
>
> Kick Ass!!!
>

>
> Yes! Wow! Was that a breeze! That class rocks!
>
> Thanks tons, Bastien!
>
> I have to admit when I first saw your reply I thought, "Oh, man,
> another class to learn? But I know this is so close to working."
>
> I look at the sample and thought, "This looks easy," and had it
> working in no time.
>
> Big thanks again!
>
> Attachments were a big deal here and this makes it a breeze, AND it
> looks like multiple attachments would be no problem?
>
> Very cool!
>
> Skip
>
> --
> ====================================
> Skip Evans
> Big Sky Penguin, LLC
> 503 S Baldwin St, #1
> Madison WI 53703
> 608.250.2720
> http://bigskypenguin.com
> ------------------------------------
> Those of you who believe in
> telekinesis, raise my hand.
> -- Kurt Vonnegut


Yep, I created a wrapper for the class and pass in attachments as an
array. Then just loop thru the array with the attachment code. It's
very easy.

Bastien

Sent from my iPod

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

Re: Sending email w/ attachments

am 11.08.2009 13:19:07 von Richard Heyes

Hi,

> ...

Sorry, quoted wrong email. Oopsy...

--
Richard Heyes
HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)

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