This topic is locked

attach file after update

12/2/2008 11:49:41 AM
PHPRunner General questions
S
szjunior author

Hello,
How can I do to send a email, using the AFTER RECORD UPDATED - send email with bew data ??
Im using a FILE/IMAGE type field.
I received the email, but the file stored in /files subdir in the server as text.
how to send the file too ?
thanks.

J
Jane 12/3/2008

Hi,
to send email with file edit standart send email with new data action.

Check examples in the PHP manual:

http://php.net/manual/en/function.mail.php#83491

S
szjunior author 12/3/2008

Ok. Its working, but could you please help me again, what i have to change for send more than one field.
In this case the field arq_xls,
I need to send the fields arq2_xls and arq3_xls (3 fields that contain files like arq_xls).
thanks .

function AfterEdit(&$values, $where, &$oldvalues, &$keys,$inline)

{

global $conn,$avalues;
$to = $values["email"];

$from = 'L';

$sendto = "$to,$cc,$bcc";
$subject = $avalues["subject"];

$message = "";
$attach = $values["arq_xls"]; <---- here is the field number 1...

$ext = str_replace('.','',strstr($attach, '.'));

$loc = "files/$attach";
$fileatt = $loc;

$fileatt_type = $ext;

$fileatt_name = $attach;
$headers = "To: $to\n" .

"From: $from\n" .

"cc: $cc\n" .

"Bcc: $bcc\n" .

"X-Mailer: PHP 5.x";
if ($fileatt) {

$file = fopen($fileatt,'rb');

$data = fread($file,filesize($fileatt));

fclose($file);
$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\r\nMIME-Version: 1.0\n" .

"Content-Type: multipart/mixed;\n" .

" boundary=\"{$mime_boundary}\"";
$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" .

$message . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .

"Content-Type: {$fileatt_type};\n" .

" name=\"{$fileatt_name}\"\n" .

//"Content-Disposition: attachment;\n" .

//" filename=\"{$fileatt_name}\"\n" .

"Content-Transfer-Encoding: base64\n\n" .

$data . "\n\n" .

"--{$mime_boundary}--\n";

}
else {
$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\r\nMIME-Version: 1.0\n" .

"Content-Type: multipart/mixed;\n" .

" boundary=\"{$mime_boundary}\"";
$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" .

$message . "\n\n" .

"--{$mime_boundary}--\n";
}
$ok = @mail($sendto, $subject, $message, $headers);
if ($ok) {

echo "<p>sent -- $fileatt</p>";

} else {

echo "<p>not sent!</p>";
}

}