Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
loraxx
Regular
Regular



Joined: Jan 24, 2008
Posts: 58

PostPosted: Mon Mar 10, 2008 9:15 am Reply with quote

I have created scripts to automatically execute a set of php commands automatically at a time interval I specify. The function I would like to do when this automatic function is called is to create an email and attach a gzip file and send it to a gmail account.


In a nutshell what is the php code or commands required to send an email with attachment that is a gzip to a gmail account.

My server does not support mutt and since this is a backup file I can not afford bit loses that occur with the standard php mail command.

Any help is appreciated. Thanks
 
View user's profile Send private message
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Mon Mar 10, 2008 11:07 am Reply with quote

The standard php mail() function doesn't lose bits, I'm not sure what you mean.

As for adding an attachment, I dunno, you might have to add a header to your message along with the properly encoded version of your attachment.

_________________
GCalendar - An Event Calendar for PHP-Nuke
Member_Map - A Google Maps Nuke Module 
View user's profile Send private message
Gremmie







PostPosted: Mon Mar 10, 2008 11:18 am Reply with quote

If you google for "php mail attachments" a few interesting things turn up.
 
loraxx







PostPosted: Mon Mar 10, 2008 4:55 pm Reply with quote

First thanks for the help Gremmie Very Happy

Gremmie wrote:
The standard php mail() function doesn't lose bits, I'm not sure what you mean.


My concern about bit loss is based on several references I have seen as I was trying to get up to speed on mail commands in php and cron

here is one from [ Only registered users can see links on this board! Get registered or login! ]

base64_encode — Encodes data with MIME base64

Description
string base64_encode ( string $data )
Encodes the given data with base64.

This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies.

Base64-encoded data takes about 33% more space than the original data.


Sorry gremmie I could not get back to other examples of things I have read that made me believe that I need to makesure the mail protocal/command/options is consistent/compatible with the data I attach.
 
Gremmie







PostPosted: Mon Mar 10, 2008 5:23 pm Reply with quote

Oh okay. Yeah that is why you have to set the proper MIME header on your attachment. If you google, you'll see example scripts that do this.
 
loraxx







PostPosted: Thu Mar 13, 2008 7:35 am Reply with quote

Gremmie,

I have achieved my objective (email gzip file via php) with the following script:

Code:
//  start send mail of backup

      $date = date('Y-m-d');
      $mail_from = "BIA auto";                                             // email from
      $mail_to = "your email";                                          // email destination
      $filename2 = "file location with filename";            // name of file to email
      
      $senddate = date("Y-m-d@h-ia");
      $subject = "Automatic Database Email of Cron Backup - $senddate";


      $fileatt_type = filetype($filename2);
      $fileatt_name = str_replace("/", "", strrchr($filename2, "/"));

      $file = fopen($filename2, 'rb');
      $data = fread($file,filesize($filename2));
      fclose($file);
      $data = chunk_split(base64_encode($data));

      $semi_rand = md5(time());
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

      $headers = "From: $mail_from <$mail_from>\n";
      $headers.= "MIME-Version: 1.0\n";
      $headers.= "Content-Type: multipart/mixed;\n";
      $headers.= " boundary=\"{$mime_boundary}\"";

      $message = "This is a multi-part message in MIME format.\n\n";
      $message.= "--{$mime_boundary}\n";
      $message.= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
      $message.= "Content-Transfer-Encoding: 7bit\n\n";
      $message.= "$dbres";
      $message. "\n\n";
      $message.= "--{$mime_boundary}\n";
      $message.= "Content-Type: {$fileatt_type};\n";
      $message.= " name=\"{$fileatt_name}\"\n";
      $message.= "Content-Disposition: attachment;\n";
      $message.= " filename=\"{$fileatt_name}\"\n";
      $message.= "Content-Transfer-Encoding: base64\n\n";
      $message.= $data . "\n\n";
      $message.= "--{$mime_boundary}--\n";

      // Send the message
      $check2 = @mail($mail_to, $subject, $message, $headers, "-f$mail_from");
             
      
//  end send mail of backup
 
Gremmie







PostPosted: Thu Mar 13, 2008 9:30 am Reply with quote

Nice research work! Awesome.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©