Mail and attachments

Miles Beck milesbeck at gmail.com
Mon Aug 21 08:03:06 MST 2006


On 8/19/06, Alex Dean <alex at crackpot.org> wrote:
> If you have PHP available, you could try the following.  It requires
> the HTMLMimeMail class from phpguru.org.  http://www.phpguru.org/
> static/mime.mail.html  That's the PHP4 version.  There's a rewritten
> version that takes advantage of the new PHP5 object model, but most
> shared hosts are still using PHP4 (unfortunately).
>
> I just bashed this out, so there may be typos, but it should be
> something to get started with.  I've used the htmlMimeMail class in
> several projects and it works very well.  This won't work well with
> large files, since the file will be read into memory before being sent.

Hm, I tried using the script and it hangs when I execute it. I'm not
sure I filled everything out the way it should be. Below is the script
as I filled it out. One thing to note, I am using $date so I can name
the file with the current date. Can this be used in your script? I've
added it to the beginning of the script.

DATE=`date +%Y%m%d`
# /usr/local/bin/php -q
php -q
<?
require_once 'htmlMimeMail.class.php';

// add as many recipients as you want
$to = array('milesbeck at gmail.com');

$mail =& new htmlMimeMail();
$attachment = $mail->getFile('/home/bluntmon/$DATE-dailybackup.tgz');
$mail->addAttachment($attachment,'filename','mime/type');
$mail->setText('');
$mail->setFrom('milesbeck at gmail.com');
$mail->setSubject('$DATE Daily Backup');
$result = $mail->send($to);

// simple check to see that mail was accepted for delivery
if($result) {
  // ok
  exit(0);
} else {
  // something went wrong
  exit(1);
}
?>


More information about the PLUG-discuss mailing list