1
Foxing
Adding Email Attachments
  • 2003/10/15 10:18

  • Foxing

  • Just popping in

  • Posts: 3

  • Since: 2003/10/12


I am having a fair bit of trouble figuring out how to send attachments via email. Those familiar with these types of message source formats will know that I need to add a short line in to the headers and then encapsulate the file in to the body with a 'head' and 'foot'.

I have looked at the functions available in:

/class/xoopsmailer.php
and
/class/mail/xoopsmultimailer.php

Apparently xoopsmultimailer.php has a class called XoopsMultiMailer which 'extends' XoopsMultiMailer the same class found in:

/class/mail/phpmailer/class.phpmailer.php

I have read the docs for the base phpmailer and it looks like it has fairly sophisticated mail attachment functions which look as though they will do exactly what I need.

My question is, how should I go about accessing them through the standard email functions built in to XOOPS 2 (xoops 2.0.5)?

Currently I have:

$xoopsMailer =& getMailer();
$xoopsMailer->useMail();
$xoopsMailer->setToEmails($xoopsConfig['adminmail']);
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
$xoopsMailer->setFromName($xoopsConfig['sitename']);
$xoopsMailer->setSubject($subject);
$xoopsMailer->setBody($message);
$xoopsMailer->send();

Which is working find, but i havent tried to attach anything yet...

I am adding:

$xoopsMailer->AddStringAttachment($dump_buffer,$filename,"base64","application/octet-stream");

$dump_buffer and $filename are defined, and have realistic values assigned to them however I receive this error when attempting to execute the page:

Fatal error: Call to undefined function: addstringattachment() in /home/site/public_html/modules/dev/test.php on line 160

Any ideas would be greatly appreciated.

2
ackbarr
Re: Adding Email Attachments

Well the only thing I can think of is since php is case-sensitive, make sure your call to the function matches exactly (note the differences in case in the error message):


$xoopsMailer->AddStringAttachment($dump_buffer,$filename,"base64","application/octet-stream");



and if your file already exists on the filesystem, you can try to use:

$xoopsMailer->AddAttachment($path,$filename,"base64","application/octet-stream");




3
onokazu
Re: Adding Email Attachments
  • 2003/10/15 12:26

  • onokazu

  • XOOPS Founder

  • Posts: 617

  • Since: 2001/12/13


The AddStringAttachment method is defined in the phpmailer class so if you need to access that method, you should use it like:

$xoopsMailer->multimailer->AddStringAttachment(...);

This is because the XoopsMailer class is not a child class of the xoopsmultimailer class, but only holds a reference to that class as a class property.

4
ackbarr
Re: Adding Email Attachments

thanks for clarifying this onokazu, I didn't realize that the get_mailer function returned the XoopsMailer class instead of the XoopsMultiMailer

5
Foxing
Re: Adding Email Attachments
  • 2003/10/16 9:57

  • Foxing

  • Just popping in

  • Posts: 3

  • Since: 2003/10/12


Nice one guys, cheers.

I'm not really a php expert, more a perly/asp kinda guy.

i have never really seen this format before:

$XXXXX->XXXXX->XXXXX(...);

But it makes sense. I wound up accessing class.phpmailer.php directly by accessing the class and functions directly (after including the file of course):


$mail = new PHPMailer();



    
$mail->From     $xoopsConfig['adminmail'];

    
$mail->FromName $xoopsConfig['sitename'];

    
$mail->Mailer   "mail";



    
$mail->Subject $subject;

    
$mail->Body    $message;

    
$mail->AddAddress($xoopsConfig['adminmail'], $xoopsConfig['sitename'], "base64""application/octet-stream");

    
$mail->AddStringAttachment($buffer$filename);



    
$mail->Send();



For anyone wondering what this thread was about and how to use the included examples, make sure that the required files are included. Form the filename in to $filename correctly, dump the file contents in to $buffer and off you go....all good.

Login

Who's Online

161 user(s) are online (105 user(s) are browsing Support Forums)


Members: 0


Guests: 161


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Jun 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits