?
Solved

PHP/Pear Mail script not sending attachments

Posted on 2010-11-23
2
Medium Priority
?
1,478 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 2000 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The new Gmail Phishing Scam going around is surprising even the savviest of users with its sophisticated techniques.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
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 …
Suggested Courses

719 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