Mail and attachments

Alex Dean alex at crackpot.org
Sat Aug 19 12:04:25 MST 2006


On Aug 19, 2006, at 11:34 AM, Miles Beck wrote:

> Greetings,
>
> I am using a shared host server and would like to be able to backup
> some files automatically and then send it to my gmail account.
>
> I'm trying to use the tools given with the shell account but I am
> unable to see the file attached as an attachment with Gmail.


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.

mailer.php :
##################################
/usr/local/bin/php -q
<?
require_once 'htmlMimeMail.class.php';

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

$mail =& new htmlMimeMail();
$attachment = $mail->getFile('/path/to/your/file');
$mail->addAttachment($attachment,'filename','mime/type');
$mail->setText('add a text message to the email if you like');
$mail->setFrom('you at yourhost.com');
$mail->setSubject('Backup File');
$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);
}
?>
##################################

The cron job would look like this :

0 0 * * * /path/to/mailer.php

I hope that helps.

alex
.





More information about the PLUG-discuss mailing list