Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHPmailer shows me a blank attachment?? 1

Status
Not open for further replies.

rogerzebra

Technical User
May 19, 2004
216
SE
Hi again friends,
I'm trying to get PHPmailer to work and the most part does, except for the last part when I want to open the document. It shows the attachment and the format of the attachment but when I'm open it, its just a blank document?? Even after saving it to disk first. If anyone have a clue of what's going on here please let me know. As usual all efforts are appreciated.
Thanks in advance
/rz
 
Insufficient data for a meaningful answer.

As a start, post the mininum necessary PHP code that will duplicate your problem.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi sleipnir,
I wasn't sure if this is the right forum for my issues, but I as usual I appreciate all help from you guys.

Code:
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { 
    $file = $path.$filename; 
    $file_size = filesize($file); 
    $handle = fopen($file, "r"); 
    $content = fread($handle, $file_size); 
    fclose($handle); 
    $content = chunk_split(base64_encode($content)); 
    $uid = md5(uniqid(time())); 
    $name = basename($file); 
    $header = "From: ".$from_name." <".$from_mail.">\r\n"; 
    $header .= "Reply-To: ".$replyto."\r\n"; 
    $header .= "MIME-Version: 1.0\r\n"; 
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; 
    $header .= "This is a multi-part message in MIME format.\r\n"; 
    $header .= "--".$uid."\r\n"; 
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; 
    $header .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
    $header .= $message."\r\n\r\n"; 
    $header .= "--".$uid."\r\n"; 
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here 
    $header .= "Content-Transfer-Encoding: base64\r\n"; 
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; 
    $header .= $content."\r\n\r\n"; 
    $header .= "--".$uid."--"; 
    if (mail($mailto, $subject, "", $header)) { 
        echo "mail send ... OK"; // or use booleans here 
    } else { 
        echo "mail send ... ERROR!"; 
    } 
} 
$my_file = "test3.pdf"; 
$my_path = $_SERVER['DOCUMENT_ROOT']."/intranet/articles/"; 

$my_name = "rp"; 
$my_mail = "newuser@localhost"; 
$my_replyto = "my_reply_to@mail.net"; 
$my_subject = "This is a test mail with attachment."; 
$my_message = "Hallo,\r\ test attachment.\r\n\r\ngr. "; 
mail_attachment($my_file, $my_path, $my_mail, $my_name, $my_replyto, $my_subject, $my_message);

So, I can send a mail and it indicates that the email has an attachments to it. It both shows the extra kbit's for the attachment and the doc file. But when I'm open it it's a blank document. What do you think of that?
 
Okay, now I have tried phpmailer aswell with the same result. I'm not able to send an email with the attachment. The email itself goes thru but not the attachment. I start to believe that it is something wrong with my configuration that's not as it should. I'm supposed to be able to send an attachment to my local adress right? Someone, any ideas?

Code:
require_once($_SERVER['DOCUMENT_ROOT'].'/intranet/config.php'); 


require_once($_SERVER['DOCUMENT_ROOT'].'/intranet/lib/MailClass.inc'); 

$mailer = new FreakMailer(); 


$mailer->Subject = 'test'; 


$mailer->Body = 'Testing mail system!'; 

$mailer->AddAddress('newuser@localhost', 'Rp'); 
$mailer->AddCC('newuser@localhost','Second Person');
$mailer->AddBCC('rpeterson@magellanins.com', 'Roger Peterson');
$mailer->AddAttachment('/localhost/intranet/articles/test3.pdf', 'test3.pdf'); 


if(!$mailer->Send()) 

{ 
 echo 'There was a problem sending this mail!'; 
} 
else 
{ 
 echo 'Mail sent!'; 
} 
$mailer->ClearAddresses(); 
$mailer->ClearAttachments(); 
?>
 
The path:

/localhost/intranet/articles/test3.pdf

interests me. Since PHP's filesystem functions operate on the entire filesytem, not just the document root, I'm wondering if the document is simply not where PHPMailer thinks it is.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks again sleipnir, believe me I tried all type of different paths. Without any luck. What else is it to configure? I did a small couple of changes in class.phpmailer variables as $From $encoding
$Mailer = "mail" etc.. I really can't see the light in the tunnel by this point...this seems to become a nightmare. ;)
 
sleipnir,

I'm sorry you were right, it was the path. Thanks again. Good job!!! :)
 
I'm sorry you were right, it was the path. Thanks again. Good job!!! :)

HI.
I am having the same problem.!
what did you change in the path to make it work.?

I want to attatch a .pdf to my emails.

the full path to the .pdf is:

my phpmailer script is in:


none of these variations works.

$mail->AddAttachment(".images/bladdabladda.pdf","bladdabladda.pdf");
$mail->AddAttachment("./images/bladdabladda.pdf","bladdabladda.pdf");
$mail->AddAttachment("/images/bladdabladda.pdf","bladdabladda.pdf");
$mail->AddAttachment("

What am I doing wrong?
 
spectrastu,
Yes, you need to use the path from your root, like so,

Code:
$mailer->AddAttachment("C:/something/something/dealers/images/bladdabladda.pdf", 'bladdabladda.pdf');

hope that helps.
/rz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top