PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mattmcb
Forum Commoner
Posts: 27 Joined: Sun Jan 25, 2004 3:34 pm
Post
by mattmcb » Thu Apr 21, 2005 10:33 am
Does anyone know why this is not working:
Code: Select all
// Send email to complete the order with WorkoutSupplies.com
$boundary = '-----=' . md5( uniqid ( rand() ) );
$len = filesize("/home/seekshop/public_html/fitness/invoices/".$HTTP_GET_VARS['oID'].".pdf");
$type = filetype("/home/seekshop/public_html/fitness/invoices/".$HTTP_GET_VARS['oID'].".pdf");
$message .= "Content-Type: application/$type; name=\"".$HTTP_GET_VARS['oID'].".pdf\"\n";
$message .= "Content-Length: $len";
$message .= "Content-Disposition: attachment; filename=\"".$HTTP_GET_VARS['oID'].".pdf\"\n\n";
$path = "/home/seekshop/public_html/fitness/invoices/".$HTTP_GET_VARS['oID'].".pdf";
$fp = fopen($path, 'r');
do //we loop until there is no data left
{
$data = fread($fp, 8192);
if (strlen($data) == 0) break;
$content .= $data;
} while (true);
$content_encode = chunk_split(base64_encode($content));
$message .= $content_encode . "\n";
$message .= "--" . $boundary . "\n";
$message_body = "Please ship the attached order for SeekShopping.com Fitness";
$headers = "From: \"SeekShopping.com Fitness\"<seekshop@seekshopping.com>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
mail('seekshop@seekshopping.com, mattmcb123@yahoo.com', 'URGENT: DROPSHIP ORDER FROM SeekShopping.com Fitness ENCLOSED', $message . $message_body, $headers);
Basically, I am trying to attach a pdf to an email and send it. The file sends but there is no attachment and no message in the body of the email.
Thanks!
choppsta
Forum Contributor
Posts: 114 Joined: Thu Jul 03, 2003 11:11 am
Post
by choppsta » Wed Apr 27, 2005 8:00 am
Firstly, I'd be concerned about using a GET variable directly in email headers and fopen's. There's potential for abuse.
Personally, I'd use phpMailer or similar:
http://phpmailer.sourceforge.net/
Then you don't have to worry about the specifics of how the email is formed and you can concentrate on the logic.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Thu Apr 28, 2005 12:33 am
Code: Select all
$string = $file;
$to = $_to;
$array = explode("/", $string);
$fileatt = $_file;
$fileatt_type = 'application/#EditTHIS';
$fileatt_name = $string = $array[sizeof($array)-1];
$headers = "From:". $_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$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}\"";
$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";