This topic is locked

Advanced Send Email Events

7/28/2007 1:43:20 PM
PHPRunner Tips and Tricks
T
teshephe author

Well since there was nothing really helpful on this site besides Simple Email I thought I wouild share this snippet of code I wrote for all to enjoy and use as they see fit.
After many, many hours of coding and testing here you go.
[color=#0000FF]function AfterAdd() // This can be put into whatever Event you wish, just make sure to change the $xvalue to the corresponding one for the event type you are using this for
{
global $conn,$avalues;
// ** Send Advanced email ****
// Read POST request params into global vars

$to = $avalues["sentTo"];

$from = $avalues["fromID"];

$cc = $avalues["cc"]";

$bcc = $avalues["bcc"];

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

$message = $avalues["detail"];
$attach = $avalues["attachment"];

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

//$type = filetype($attach);

//$mime = mime_content_type($attach);

$loc = "UPLOADS/EMAILATTACH/$attach";
// Obtain file upload vars

$fileatt = $loc;

$fileatt_type = $ext;

$fileatt_name = $attach;
//$headers = "From: $from\r\n" . "Cc: $cc\n" . "Bcc: $bcc\n";
$headers = "To: $to\n" .

"From: $from\n" .

"cc: $cc\n" .

"Bcc: $bcc\n" .

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

// Read the file to be attached ('rb' = read binary)

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

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

fclose($file);
// Generate a boundary string

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment

$headers .= "\r\nMIME-Version: 1.0\n" .

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

" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message

$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";
// Base64 encode the file data

$data = chunk_split(base64_encode($data));
// Add file attachment to the message

$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 {
// Generate a boundary string

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers

$headers .= "\r\nMIME-Version: 1.0\n" .

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

" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message

$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";
}
// Send the message

$ok = @mail($sendto, $subject, $message, $headers);
if ($ok) {

echo "<p>Mail sent! Yay PHPRunner! With File Attachement: $fileatt</p>";

} else {

echo "<p>Mail could not be sent. Sorry!</p>";

C
ckapote 5/19/2011

fantastic Well Done !!
It is working GReat

A
Alto 6/22/2011



Well since there was nothing really helpful on this site besides Simple Email I thought I wouild share this snippet of code I wrote for all to enjoy and use as they see fit.
After many, many hours of coding and testing here you go.
[color="#0000FF"]function AfterAdd() // This can be put into whatever Event you wish, just make sure to change the $xvalue to the corresponding one for the event type you are using this for
{
global $conn,$avalues;
// ** Send Advanced email ****
// Read POST request params into global vars

$to = $avalues["sentTo"];

$from = $avalues["fromID"];

$cc = $avalues["cc"]";

$bcc = $avalues["bcc"];

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

$message = $avalues["detail"];
$attach = $avalues["attachment"];

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

//$type = filetype($attach);

//$mime = mime_content_type($attach);

$loc = "UPLOADS/EMAILATTACH/$attach";
// Obtain file upload vars

$fileatt = $loc;

$fileatt_type = $ext;

$fileatt_name = $attach;
//$headers = "From: $from\r\n" . "Cc: $cc\n" . "Bcc: $bcc\n";
$headers = "To: $to\n" .

"From: $from\n" .

"cc: $cc\n" .

"Bcc: $bcc\n" .

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

// Read the file to be attached ('rb' = read binary)

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

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

fclose($file);
// Generate a boundary string

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment

$headers .= "\r\nMIME-Version: 1.0\n" .

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

" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message

$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";
// Base64 encode the file data

$data = chunk_split(base64_encode($data));
// Add file attachment to the message

$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 {
// Generate a boundary string

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers

$headers .= "\r\nMIME-Version: 1.0\n" .

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

" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message

$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";
}
// Send the message

$ok = @mail($sendto, $subject, $message, $headers);
if ($ok) {

echo "<p>Mail sent! Yay PHPRunner! With File Attachement: $fileatt</p>";

} else {

echo "<p>Mail could not be sent. Sorry!</p>";



I could put this Fantastic code in a button?(phprunner 5.3)

D
doykoes 9/30/2011



I could put this Fantastic code in a button?(phprunner 5.3)


Here my error...? Can Help...?

filesize() [function.filesize]: stat failed for UPLOADS/EMAILATTACH/