Solved

PHP/Pear Mail script not sending attachments

Posted on 2010-11-23
2
1,437 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
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now