Log in

View Full Version : Problem with mail::factory - attachments



AikenD
06-21-2007, 03:25 PM
Hi guys !

Very new to PHP, hardcore DB though :-)

I am having a problem sending attachments in an email (PEAR MIME)

I have a requirement to send emails with 6 attachments (always the same 6 attachments)

When I send 3 attachments, everything is fine, but more than 3 cause the page to return blank. The code below has 4 attachments, unless I comment out the 4th attachment, nothing will work !
I'm going crazy here, any help greatly appreciated :-((

Code:

<?php
require_once('Mail.php');
require_once('Mail/mime.php');

$text = 'Text version of email';
// $file = 'lightning.jpg';
$crlf = "\n";
$hdrs = array(
'From' => $sender,
'Subject' => $subject
);

$mime = new Mail_mime($crlf);

$mime->setTXTBody($text);

// Add first file
// $status = $mime->addAttachment($file, 'image/jpeg');

// Add more files
$status = $mime->addAttachment( 'PICT8461.JPG', 'image/jpeg');
$status = $mime->addAttachment( 'PICT8462.JPG', 'image/jpeg');
$status = $mime->addAttachment( 'PICT8463.JPG', 'image/jpeg');
// $status = $mime->addAttachment( 'PICT8464.JPG', 'image/jpeg');

if( PEAR::isError( $status ) ) {
echo "<p>addAttachment( ) returned with error ".$status->getMessage()."</p>\n";
}

$body = $mime->get();

// Call after body has been set from $mime
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory( 'smtp');
$status = $mail->send($recipient, $hdrs, $body);
if( PEAR::isError( $status ) ) {
echo "<p>Error sending mail: ".$status->getMessage()."</p>\n";
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test Mail</title>
</head><body>
<h1>Test Mail</h1>
<p>Mail sent!</p>
</body></html>