Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Define types of messages. For the use of simpleinvoices, only html messages will be sent.
- $htmlbody =
- "
- <h3>INVOICE</h3>
- <br />
- ---------------------------------------------------------
- <br />
- Invoice Summary
- <br />
- ---------------------------------------------------------
- <br />
- Invoice ID:
- "
- .
- $invoice['index_id']
- .
- "
- <br />
- Issue Date:
- "
- .
- $invoice['date']
- .
- "
- <br />
- Customer:
- "
- .
- $customer['name']
- .
- "
- <br />
- Amount:
- "
- .
- '$'.round($invoice['total'], 2)
- .
- "
- <br />
- Due:
- "
- .
- '15 days from '.$invoice['date'].' (Net 15)'
- .
- "
- <br />
- Notes:
- "
- .
- $invoice['note']
- .
- "
- <br />
- <br />
- A detailed invoice is attached as a PDF.
- <br />
- <br />
- "
- .
- "
- ----------------------------------------------------------
- <br />
- "
- .
- $_POST['email_notes'];
- $textmessage = $_POST['email_notes'];
- //define the receiver of the email
- $to = $_POST['email_to'];
- //define the subject of the email
- $subject = $_POST['email_subject'];
- //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: " . $biller['name'] . "<" . $_POST['email_from'] . ">" . "\r\nReply-To: " . $_POST['email_from'] . "\r\nBcc: " . $_POST['email_bcc'];
- //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('./tmp/cache/' . $pdf_file_name))); ;
- //define the body of the message.
- $message = "--PHP-mixed-$random_hash\r\n"
- ."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
- $message .= "--PHP-alt-$random_hash\r\n"
- ."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
- ."Content-Transfer-Encoding: 7bit\r\n\r\n";
- //Insert the plain text message.
- $message .= strip_tags($textmessage);
- $message .= "\r\n\r\n--PHP-alt-$random_hash\r\n"
- ."Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
- ."Content-Transfer-Encoding: 7bit\r\n\r\n";
- //Insert the html message.
- $message .= $htmlbody;
- $message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";
- //include attachment
- $message .= "--PHP-mixed-$random_hash\r\n"
- ."Content-Type: application/pdf; name=$pdf_file_name\r\n"
- ."Content-Transfer-Encoding: base64\r\n"
- ."Content-Disposition: attachment\r\n\r\n";
- $message .= $attachment;
- $message .= "/r/n--PHP-mixed-$random_hash--";
- //send the email
- $mail_sent = @mail( $to, $subject, $message, $headers );
- //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
- $sent = $mail_sent ? $pdf_file_name . " was sent to " . $_POST['email_to'] . " successfully." : "The invoice was not sent. Please try again.";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement