wmguk Posted March 24, 2009 Share Posted March 24, 2009 Hey, I've got a mail script that attaches a PDF with the order... <?php $name = $_GET['company']; $email = $_GET['email']; $order_id = $_GET['id']; //define the receiver of the email $to = '[email protected]'; //define the subject of the email $subject = 'Online Order'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: " . "$name" . "<" . "$email" . ">"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents('$order_id.pdf'))); //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello World!!! This is simple text email message. --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <h2>Hello World!</h2> <p>This is something with <b>HTML</b> formatting.</p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: application/zip; name="<?php echo $order_id; ?>.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?> I get "mail sent" on the page and I receive the email with the pdf attachment, however its corrupted when it gets to me... I think it is this line: $attachment = chunk_split(base64_encode(file_get_contents('$order_id.pdf'))); I think its that because i think im setting the attachment to $order_id.pdf and not 14.pdf if i set it to 14.pdf it works... Any thoughts on what is stopping this working? Link to comment https://forums.phpfreaks.com/topic/150934-solved-attaching-pdf-files/ Share on other sites More sharing options...
kittrellbj Posted March 24, 2009 Share Posted March 24, 2009 The single-quotes might be the culprit. Try $pdf = $order_id . ".pdf"; before the statement and then $pdf (without quotes) where you have '$order_id.pdf'. Link to comment https://forums.phpfreaks.com/topic/150934-solved-attaching-pdf-files/#findComment-792949 Share on other sites More sharing options...
wmguk Posted March 24, 2009 Author Share Posted March 24, 2009 excellent!!!! thank you Link to comment https://forums.phpfreaks.com/topic/150934-solved-attaching-pdf-files/#findComment-792964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.