PEAR Packages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPEAR Packages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 23rd, 2009, 06:03 AM
Darko74 Darko74 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 2 Darko74 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 17 sec
Reputation Power: 0
Question Sending Mail_mime with attached image

I'm trying to use the Mail_mime class in order to send an e-mail with an attached image. Everything works except for the image. The e-mail recipient doesn't get any attached file.

I started from this point to write my code:

pear.php.net/manual/en/package.mail.mail-mime.example.php
(I couldn't write the whole URL)

And this is what I wrote:

PHP Code:
<?php
// Use of PEAR libraries


// Store raw post data obtained from flash
if (isset($HTTP_RAW_POST_DATA)) {
    
$inputData fopen('php://input','rb');
    
$image stream_get_contents($inputData);
    
fclose($inputData);     
}

require(
'Mail.php');
require(
'Mail/mime.php');

$text 'Hello dude! Here\'s your image!';
$html '<html><body>Hello dude! Here\'s your image!</body></html>';

$crlf "\n";
$hdrs = array(
              
'From'    => 'myself@hotmail.com',
              
'To'    => 'myself@hotmail.com',
              
'Subject' => 'MIME message test with attached image'
              
);

$mime = new Mail_mime($crlf);

$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($image'application/octet-stream');

//do not ever try to call these lines in reverse order
$body $mime->get();
$hdrs $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send('info@receiver.com'$hdrs$body);
?>


In comparison to the example in the PEAR web, the only difference is that I have to get raw post data sent from flash (the image bytes) and use them in the addAttachment() method instead of just a plain text.

The recipient e-mail client receives this e-mail, with the correct "From:" and "Reply-To" info, the correct subject and message body...., but there is no image.

What am I doing wrong?

P.S.: I also tried adding $HTTP_RAW_POST_DATA to the 1st parameter of the addAttachment() method, like this:
addAttachment($HTTP_RAW_POST_DATA, 'application/octet-stream');

Reply With Quote
  #2  
Old July 23rd, 2009, 07:44 AM
wiesemann wiesemann is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 172 wiesemann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 2 m
Reputation Power: 3
You should receive an error message if would check for errors (via PEAR::isError()).

For debugging, you can add these lines at the beginning of your script:
Code:
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'PEAR.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);


But the solution to your problem seems to be to use the fourth parameter of the addAttachment() call:
http://pear.php.net/manual/en/package.mail.mail-mime.addattachment.php

Reply With Quote
  #3  
Old July 23rd, 2009, 02:48 PM
Darko74 Darko74 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 2 Darko74 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 17 sec
Reputation Power: 0
Thanks a lot for your help!

I had to specify the 4th parameter ($isfile) to false because the default is true.

Best regards!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > Sending Mail_mime with attached image


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek