0

Possible Duplicate:
How to send email with attachment using PHP?
PHP mail() attachment problems

I'm trying to implement this script: Send PHP HTML mail with attachments

The only thing I've modified in the script was the send-to address and the file. I'm trying to attach an .mp3 file instead of a .zip file - maybe this is the reason I'm getting unexpected results?

The .mp3 file is only 31kb

But when I receive the email, there is no attachment and no HTML formatting in the message.

The email message contains:

--PHP-mixed-a80d597fc7c02e67ff5be867c7a48bab
Content-Type: multipart/alternative; boundary="PHP-alt-a80d597fc7c02e67ff5be867c7a48bab"

--PHP-alt-a80d597fc7c02e67ff5be867c7a48bab
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

--PHP-alt-a80d597fc7c02e67ff5be867c7a48bab
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>

--PHP-alt-a80d597fc7c02e67ff5be867c7a48bab--

--PHP-mixed-a80d597fc7c02e67ff5be867c7a48bab
Content-Type: application/zip; name="attachment.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

SUQzAwAAAAABIVRQRTEAAAAfAAAB//5DAGgAZQBlAHMAZQBDA.....
Community
  • 1
  • 1
  • 1
    Why don't you use something like SwiftMailer or PHPMailer if you're overwhelmed with MIME construction? – mario Oct 04 '12 at 21:44
  • I won't answer your question because it's really painful to send an html email using PHP from scratch when there is Swiftmailer for example .. – j0k Oct 04 '12 at 21:45
  • found my answer here: http://stackoverflow.com/questions/6275070/php-mail-attachment-problems – user1160050 Oct 04 '12 at 21:50
  • Found my solution here: http://stackoverflow.com/questions/6275070/php-mail-attachment-problems – user1160050 Oct 04 '12 at 22:10

1 Answers1

0

I am looking at this line in your mail:

Content-Type: application/zip; name="attachment.zip"

You are attaching a mp3 file, so your content type should be audio/mpeg3 and the filename should be according to whatever you are sending.

Content-Type: audio/mpeg3; name="somefile.mp3"

Also - be careful of the 64 bit encoding. You have to encode the mp3 in order to mail it, because you will again get unexpected results if you don't.

Brdavs
  • 35
  • 3