Re: Problem Mailing PDF using Mime
| From: | Klaus Guenther | Date: | Fri, 09 Sep 2005 16:10:48 +0000 |
| Subject: | Re: Problem Mailing PDF using Mime | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20882@lists.php.net to get a copy of this message | ||
Sorry to reply on top, but it sounds like you may be lacking a linefeed
or two at the top of the generated email (below the headers, maybe). Do
a var_dump and see. Or something like that. I think it is exclusively a
linefeed issue.
Klaus
On 9/9/2005 6:07 PM, Brian Drexler spake the following words:
>Not sure if this matters, but this machine is using Postfix for the MTA
>instead of Sendmail...
>
>-----Original Message-----
>From: Brian Drexler [mailto:bdrexler@saginawcontrol.com]
>Sent: Friday, September 09, 2005 11:06 AM
>To: pear-general@lists.php.net
>Subject: [PEAR] Problem Mailing PDF using Mime
>
>Ok, here's my issue. I'm sending a mail message with a PDF attachment using
>a script I wrote probably a year or two ago. It worked fine on my RedHat
>6.2 machine running PHP version 4.3.11. Now I'm running SUSE 9.1 with PHP
>4.4.0. If I send the e-mail to anyone using Outlook/Mozilla Thunderbird for
>a client it works fine, but when I try sending it to my gmail account for
>instance, it mashes all the headers and everything into the body of the
>message and my PDF becomes text in the body of the message. Anyone have any
>ideas? Here is basically the script I'm using with a default PEAR/Mime/Mail
>configuration.
>
>
>
><?php
>
> require_once('/usr/local/lib/php/Mail.php'); // These two files are
>par
>
>t of Pear,
>
> require_once('/usr/local/lib/php/Mail/mime.php'); // and are required
>for th
>
>e Mail_Mime class
>
>
>
> $to = "myaddress@gmail.com";
>
> $from = "myaddress@mywork.com";
>
> $subject = "This is a test email";
>
> $attachment = "/tmp/Quote14-63344.pdf";
>
>
>
> // Next we must build an array of email headers for the email.
>
> // This is structured slightly differently to the mail() function.
>
> // The array key is the header name. Remember that subject
>
> // is a header too!
>
> $headers = array('From' => $from,
>
> 'Subject' => $subject);
>
>
>
> // Here we create the plaintext version of the email to be sent
>
> $textMessage = "Dear John,\n\nThis is a fake email, I hope you enjoy
>it.\n\n
>
>>From Jane.";
>
>
>
> // Here we create the HTML version of the email to be send, using
>
> // the heredoc syntax
>
> $htmlMessage = <<<EOF
>
><html>
>
> <body bgcolor="#ffffff">
>
> <p align="center">
>
> <b>Hello World!</b>
>
> </p>
>
> </body>
>
></html>
>
>EOF;
>
>
>
> $mime = new Mail_Mime();
>
> // create a new instance of the Mail_Mime class
>
> $mime->setTxtBody($textMessage);
>
> // set our plaintext message
>
> $mime->setHtmlBody($htmlMessage);
>
> // set our HTML message
>
> $mime->addAttachment($attachment);
>
> // attach the file to the email
>
>
>
> $body = $mime->get();
>
> // This builds the email message and returns it to $body.
>
> // This should only be called after all the text, html and
>
> // attachments are set.
>
>
>
> $hdrs = $mime->headers($headers);
>
> // This builds the corresponding headers for the plaintext,
>
> // HTML and any other required headers. It also includes
>
> // the headers we created earlier by passing them as an argument.
>
>
>
> $mail = &Mail::factory('mail');
>
> // Creates an instance of the mail backend that we can use
>
> // to send the email.
>
>
>
> $mail->send($to, $hdrs, $body);
>
> // Send our email, according to the address in $to, the email
>
> // headers in $hdrs, and the message body in $body.
>
>?>
>
>
>