Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

OT: Email attachments with PHP?

LEGEND ,
Oct 09, 2006 Oct 09, 2006

Copy link to clipboard

Copied

I want to send an email with a file attachment.

Is there an easy way to do this, or is it as arcane as I think it is?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================



TOPICS
Server side applications

Views

491
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2006 Oct 09, 2006

Copy link to clipboard

Copied

Murray *ACE* wrote:
> I want to send an email with a file attachment.
>
> Is there an easy way to do this, or is it as arcane as I think it is?

http://phpmailer.sourceforge.net/

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2006 Oct 09, 2006

Copy link to clipboard

Copied

Easiest way is to use a pre made PHP class, such as PHP Mailer

http://phpmailer.sourceforge.net/

Allows you to easily send attachments with your email messages. It can
obviously be done with your own PHP code, but its *much* easier to use
something like the class above than trying to code it yourself.

Scroll down the page above, and in the example it shows you how to send
attachments

Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2006 Oct 09, 2006

Copy link to clipboard

Copied

Thank you both. I was not aware of this nice class!

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"gareth" <gareth@buzzinet.co.uk> wrote in message
news:egdm3j$q52$1@forums.macromedia.com...
> Easiest way is to use a pre made PHP class, such as PHP Mailer
>
> http://phpmailer.sourceforge.net/
>
> Allows you to easily send attachments with your email messages. It can
> obviously be done with your own PHP code, but its *much* easier to use
> something like the class above than trying to code it yourself.
>
> Scroll down the page above, and in the example it shows you how to send
> attachments
>
> Gareth
> http://www.phploginsuite.co.uk/
> PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.
>


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2006 Oct 09, 2006

Copy link to clipboard

Copied

On 09 Oct 2006 in macromedia.dreamweaver.appdev, Murray *ACE* wrote:

> I want to send an email with a file attachment.
>
> Is there an easy way to do this, or is it as arcane as I think it is?

php.net knows all, tells all:

Note: Email with attachments and special types of content (e.g.
HTML) can be sent using this function. This is accomplished via
MIME-encoding - for more information, see this Zend article or the
PEAR Mime Classes.

http://www.php.net/manual/en/function.mail.php

Refers to:

Zend article: http://www.zend.com/zend/spotlight/sendmimeemailpart1.php
PEAR Mime classes: http://pear.php.net/package/Mail_Mime

But the short version:
- encode the attachment. This is normally done for you by your mail
client; it's easy enough to find software to do it. You can even
convince PHP to do it on the fly.
- create the message as mime-encoded:
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="=====================_100756562==_"
- Add your text
- Add a boundary:
--=====================_100756562==_
- Add your mime-encoded content:
Content-Type: image/jpeg; name="glynn.jpg";
x-mac-type="4A504547"; x-mac-creator="4A565752"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="glynn.jpg"

/9j/4AAQSkZJRgABAgEBLAEsAAD/7QE0UGhvdG9zaG9wIDMuMAA4QklNA+ 0AAAAAABABLAAAAAEA
[snip - a couple hundred lines of a picture of my cousin-in-law]
NMokXJxiPRPvNZto/J/DTEWeNVIlnU0LPQci4ahr8xlXUW3y2ieF+c+tmQ6jeeqvF/WfkKg9/bN5
i5PL6i+LdLBTjv0ybU4gUap2pvXAppD706b4Wp//2Q==
- And finally, terminate the attachment:
--=====================_100756562==_--

I'd build this step-by-step, thus:

<?php
$message = "Mime-Version: 1.0\nContent-Type: multipart/mixed;\nboundary=\"=====================_100756562==_\"\n";
$message .= "Here's the file you requested\n\n";
$message .= "--=====================_100756562==_\n";
$message .= $encodedFileFromSomewhereElse; . "\n"
$message .= "--=====================_100756562==_\n";
// Continue creating the message
// ...
?>

Example message, created by Eudora, snagged off my server as a raw message:

X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0
Date: Mon, 09 Oct 2006 10:28:32 -0400
To: joe@example.org
From: Joe Makowiec <makowiec@example.com>
Subject: Mime-encoded message
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="=====================_100756562==_"

--=====================_100756562==_
Content-Type: text/plain; charset="us-ascii"; format=flowed
Text content goes here


Joe

--=====================_100756562==_
Content-Type: image/jpeg; name="glynn.jpg";
x-mac-type="4A504547"; x-mac-creator="4A565752"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="glynn.jpg"

/9j/4AAQSkZJRgABAgEBLAEsAAD/7QE0UGhvdG9zaG9wIDMuMAA4QklNA+0AAAAAABABLAAAAAEA
[snip]
NMokXJxiPRPvNZto/J/DTEWeNVIlnU0LPQci4ahr8xlXUW3y2ieF+c+tmQ6jeeqvF/WfkKg9/bN5
i5PL6i+LdLBTjv0ybU4gUap2pvXAppD706b4Wp//2Q==
--=====================_100756562==_--

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/email.php

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2006 Oct 09, 2006

Copy link to clipboard

Copied

That's arcane. 8)

PHPMailer - that's easy! 8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Joe Makowiec" <makowiec@invalid.invalid> wrote in message
news:Xns98576D05C7A09makowiecatnycapdotrE@216.104.212.96...
> On 09 Oct 2006 in macromedia.dreamweaver.appdev, Murray *ACE* wrote:
>
>> I want to send an email with a file attachment.
>>
>> Is there an easy way to do this, or is it as arcane as I think it is?
>
> php.net knows all, tells all:
>
> Note: Email with attachments and special types of content (e.g.
> HTML) can be sent using this function. This is accomplished via
> MIME-encoding - for more information, see this Zend article or the
> PEAR Mime Classes.
>
> http://www.php.net/manual/en/function.mail.php
>
> Refers to:
>
> Zend article: http://www.zend.com/zend/spotlight/sendmimeemailpart1.php
> PEAR Mime classes: http://pear.php.net/package/Mail_Mime
>
> But the short version:
> - encode the attachment. This is normally done for you by your mail
> client; it's easy enough to find software to do it. You can even
> convince PHP to do it on the fly.
> - create the message as mime-encoded:
> Mime-Version: 1.0
> Content-Type: multipart/mixed;
> boundary="=====================_100756562==_"
> - Add your text
> - Add a boundary:
> --=====================_100756562==_
> - Add your mime-encoded content:
> Content-Type: image/jpeg; name="glynn.jpg";
> x-mac-type="4A504547"; x-mac-creator="4A565752"
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename="glynn.jpg"
>
> /9j/4AAQSkZJRgABAgEBLAEsAAD/7QE0UGhvdG9zaG9wIDMuMAA4QklNA+
> 0AAAAAABABLAAAAAEA
> [snip - a couple hundred lines of a picture of my cousin-in-law]
>
> NMokXJxiPRPvNZto/J/DTEWeNVIlnU0LPQci4ahr8xlXUW3y2ieF+c+tmQ6jeeqvF/WfkKg9/bN5
> i5PL6i+LdLBTjv0ybU4gUap2pvXAppD706b4Wp//2Q==
> - And finally, terminate the attachment:
> --=====================_100756562==_--
>
> I'd build this step-by-step, thus:
>
> <?php
> $message = "Mime-Version: 1.0\nContent-Type:
> multipart/mixed;\nboundary=\"=====================_100756562==_\"\n";
> $message .= "Here's the file you requested\n\n";
> $message .= "--=====================_100756562==_\n";
> $message .= $encodedFileFromSomewhereElse; . "\n"
> $message .= "--=====================_100756562==_\n";
> // Continue creating the message
> // ...
> ?>
>
> Example message, created by Eudora, snagged off my server as a raw
> message:
>
> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0
> Date: Mon, 09 Oct 2006 10:28:32 -0400
> To: joe@example.org
> From: Joe Makowiec <makowiec@example.com>
> Subject: Mime-encoded message
> Mime-Version: 1.0
> Content-Type: multipart/mixed;
> boundary="=====================_100756562==_"
>
> --=====================_100756562==_
> Content-Type: text/plain; charset="us-ascii"; format=flowed
> Text content goes here
>
>
> Joe
>
> --=====================_100756562==_
> Content-Type: image/jpeg; name="glynn.jpg";
> x-mac-type="4A504547"; x-mac-creator="4A565752"
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename="glynn.jpg"
>
> /9j/4AAQSkZJRgABAgEBLAEsAAD/7QE0UGhvdG9zaG9wIDMuMAA4QklNA+0AAAAAABABLAAAAAEA
> [snip]
> NMokXJxiPRPvNZto/J/DTEWeNVIlnU0LPQci4ahr8xlXUW3y2ieF+c+tmQ6jeeqvF/WfkKg9/bN5
> i5PL6i+LdLBTjv0ybU4gUap2pvXAppD706b4Wp//2Q==
> --=====================_100756562==_--
>
> --
> Joe Makowiec
> http://makowiec.net/
> Email: http://makowiec.net/email.php


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2006 Oct 09, 2006

Copy link to clipboard

Copied

On 09 Oct 2006 in macromedia.dreamweaver.appdev, Murray *ACE* wrote:

> That's arcane. 8)
>
> PHPMailer - that's easy! 8)

Just took a look at it. Sure 'nuf.

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/email.php

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2006 Oct 09, 2006

Copy link to clipboard

Copied

LATEST
On Mon, 9 Oct 2006 10:38:18 -0400, "Murray *ACE*"
<forums@HAHAgreat-web-sights.com> wrote:

>Thank you both. I was not aware of this nice class!

You might this extensive tutorial helpful, Murray.

http://www.phpfreaks.com/print.php?cmd=tutorial&tut_id=130
--
Steve
steve at flyingtigerwebdesign dot com

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines