Solved

PHP/Pear Mail script not sending attachments

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Pop culture is prime bait for hackers seeking to infect user’s computers and mobile devices with malicious malware. Hackers know exactly what the latest trends are online and know how to use them to their advantage.
In this video we show how to create an Accepted Domain 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 >> Ac…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

839 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