Solved

PHP/Pear Mail script not sending attachments

Posted on 2010-11-23
2
1,463 Views
Last Modified: 2013-11-30
Hi,

I am writing a php application, and one part of the requirement is to mail a pdf file to someone.

I downloaded a script to use as my mail server needs smtp authentication etc.

Whilst the script DOES generate an email as expected, the actual email has loads of random rubbish in the body.

I changed the mime type to application/pdf but still I get loads of rubbish and no actual attachment.

I have shown the code from my script - can someone please fix it for me?

Thanks.
include('Mail.php');
include('Mail/mime.php');
 
$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = './quote.pdf';
$crlf = "rn";
$hdrs = array(
              'From'    => 'xxx@xxx.co.uk',
              'To'      => 'xxx.xxx@xxx.com',
              'Subject' => 'Your Quotation'
              );
			  
$params = array(
				'host' => "ssl://mail.xxx.co.uk",
				'port' => "465",
				'username' => "xxx",
				'password' => "xxx"
				);
 
    $mime = new Mail_mime($crlf);
 
        $mime->setTXTBody($text);
        $mime->setHTMLBody($html);
 
        $mime->addAttachment($file,'application/pdf');
 
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
 
$mail =& Mail::factory('smtp', $params);
$mail->send('xxx@xxx.com', $hdrs, $body);

Open in new window

0
Comment
Question by:MrGeeezer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
kivan24 earned 500 total points
ID: 34203829
Correct line #7, You wrote:
$crlf = "rn";

Open in new window

must be:
$crlf = "\n";

Open in new window

or don't set the $crlf parameter in line #21
$mime = new Mail_mime();

Open in new window



Normally, it is not necessary to set the $crlf parameter. But, if you want to send the generated MIME message using Mail then you have to set $crlf to "\n"
0
 

Author Closing Comment

by:MrGeeezer
ID: 34209496
Perfect - many thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
The viewer will learn how to count occurrences of each item in an array.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question