Home > Archive > PHP Programming > October 2007 > trying to understand example code for Mail_mimePart::addsubpart()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
trying to understand example code for Mail_mimePart::addsubpart()
|
|
| hmbscully 2007-10-24, 7:02 pm |
| I am trying to send a complex mutli-part email with inline attachments
between html pieces.
I originally wrote the code in Perl with the MIME::Lite module, which
worked fine. My attempts to convert the code to PHP have ended in
frustration so far. It seems when I search, all roads point me to
PEAR's Mail_mimePart, but I am not understanding the example code
enough to try to use it.
Can someone help me start to figure out how this code works?
The example code is:
<?php
include 'Mail/mimePart.php';
....
$params['content_type'] = 'multipart/mixed';
$email = new Mail_mimePart('', $params);
// Here we add a text part to the multipart we have
// already. Assume $body contains plain text.
$params['content_type'] = 'text/plain';
$params['encoding'] = '7bit';
$text = $email->addSubPart($body, $params);
// Now add an attachment. Assume $contents is
// the contents of the attachment
$params['content_type'] = 'application/zip';
$params['encoding'] = 'base64';
$params['disposition'] = 'attachment';
$params['dfilename'] = 'example.zip';
$attach =& $email->addSubPart($contents, $params);
// Now build the email. Note that the encode
// function returns an associative array containing two
// elements, body and headers. You will need to add extra
// headers, (eg. Mime-Version) before sending.
$email = $email->encode();
$email['headers']['Mime-Version'] = '1.0';
....
?>
What I don't understand at all are the
$text = $email->addSubPart($body, $params);
and
$attach =& $email->addSubPart($contents, $params);
lines in that I don't understand why there are the $text and $attach
variables, because they never seem to be used again.
I also don't know how to actually send the message.
My attempt to finish the script had me adding this:
$email =& Mail::factory('mail');
$email->send($to_email, $email['headers'], $email['body'] );
Which throws errors about things not being objects.
Is there anywhere that there is example code for how to do a complex
multi-part message?
I've tried this so many ways, with and without the PEAR code and
nothing can replicate what the Perl code creates.
| |
|
| On Oct 24, 5:43 pm, hmbscully <wdec...@gmail.com> wrote:
> What I don't understand at all are the
> $text = $email->addSubPart($body, $params);
> and
> $attach =& $email->addSubPart($contents, $params);
the variables might be there just to hold the return of the function
> lines in that I don't understand why there are the $text and $attach
> variables, because they never seem to be used again.
> I also don't know how to actually send the message.
> $email =& Mail::factory('mail');
about this line i guess this is Perl not PHP you are trying to add
if you want to call a function from a class you should do it like this
$object-name->function_name('param');
|
|
|
|
|