Forum Moderators: coopster

Message Too Old, No Replies

email script bug

         

jackvull

10:24 am on Jul 23, 2008 (gmt 0)

10+ Year Member



I receive the first email from this with 3 attachments.
However, the 2nd part after the unset commands doesn't work.
ANy ideas?


set_time_limit ( 0 );
$date = date("Ymd");

$to = "email@googlemail.com";
$from = "webserver@example.net";
$from_name = "Backups";

$subject = "Daily Backup";
$message = "Daily Backup";

$attachments = array();
$attachments[0]="../Backups/sp".$date.".tar.gz";
$attachments[1]="../Backups/Bg".$date.".tar.gz";
$attachments[2]="../Backups/DatabaseBackups".$date.".tar.gz";
send_email($to, $from, $from_name, $subject, $message, $attachments);

unset ($attachments[2]);
unset ($attachments[1]);
unset ($attachments[0]);
$attachments[0]="../Backups/sidekick".$date.".tar.gz";
send_email($to, $from, $from_name, $subject, $message, $attachments);

[edited by: eelixduppy at 1:17 pm (utc) on July 23, 2008]

janharders

10:30 am on Jul 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



exactly what isn't working? you receive no email or you receive one with the wrong attachments?
have you made sure that the file you're trying to send exist?
what does the function send_email look like?

jackvull

11:03 am on Jul 23, 2008 (gmt 0)

10+ Year Member



the first send_email command works and I get 3 attachments.
The 2nd send_email command does not woro, I received no email. The filed definitely exists.

function is:


function send_email($to, $from, $from_name, $subject, $message, $attachments=false)
{
$headers = "From: ".$from_name."<".$from.">\n";
$headers .= "Reply-To: ".$from_name."<".$from.">\n";
$headers .= "Return-Path: ".$from_name."<".$from.">\n";
$headers .= "Message-ID: <".time()."-".$from.">\n";
$headers .= "X-Mailer: PHP v".phpversion();

$msg_txt="";
$email_txt = $message;

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

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$email_txt .= $msg_txt;

$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_txt . "\n\n";

if ($attachments !== false)
{
for($i=0; $i < count($attachments); $i++)

if (is_file($attachments[$i]))
{
$fileatt = $attachments[$i];
$fileatt_type = "application/octet-stream";
$start= strrpos($attachments[$i], '/') == -1 ? strrpos($attachments[$i], '//') : strrpos($attachments[$i], '/')+1;
$fileatt_name = substr($attachments[$i], $start, strlen($attachments[$i]));

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";

}
}

$email_message .= "--{$mime_boundary}--\n";

return mail($to, $subject, $email_message, $headers);

}

mrscruff

1:55 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



have you tried:

unset ($attachments[0]);
$attachments = array();
$attachments[0]="../Backups/sidekick".$date.".tar.gz";

Aslo noticed you tend to use:
$var = "../".$var."/..";

As it is double qutoes you can place the var straightin, eg:
$var = "../$var/..";

jackvull

3:30 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



No, still doesn't work, I get no error messages either.
The file is a 17Mb file, could that be an issue somewhere?

jackvull

4:20 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



It appears the host has a 10Mb limit on email messages.
How can I split files larger tahn 10Mb into 10Mb chunks and email those instead?
The following split command doesn't work

unset ($attachments[2]);
unset ($attachments[1]);
unset ($attachments[0]);
$attachments = array();

$path = "/bin/split -b n m 10 /mounted-storage/home1/sub002/sc183-LGVN/Backups/side".$date.".tar.gz new";
$c_pid = system($path, $retval);
$attachments[0]="../Backups/side".$date.".tar.gz";
send_email($to, $from, $from_name, $subject, $message, $attachments);

eelixduppy

5:55 am on Jul 24, 2008 (gmt 0)



>> doesn't work

Can you elaborate? Are you getting any errors? Are you running in safe mode? Have you tried running this commands directly from the console? Have you tried echoing out

$path
to see if it contains what you think it contains?