Solved

PHP/Pear Mail script not sending attachments

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this video we show how to create an email address policy 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 Mail Flow…
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…

867 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

21 Experts available now in Live!

Get 1:1 Help Now