Thursday, July 16, 2015

How to Sending a PDF File Attachment Through Email With PHP and MySQL

PDF records or Portable Document Format stands are as a rule utilized for the documentation of the transaction. Since the shape that is regularly utilized as a read-just reinforcement information to be filed. Illustrations of the utilization of a PDF index ready to go provisions for example Invoice, Receipt of Goods, Proof of Registration and alternates.
So the method, clients enroll by rounding out the enlistment structure then afterward click Submit, the information is then recovered to the enlistment table. The information is as of now archived in the table can be messaged to the client in the type of a PDF index connection.
now let see how it work :)
first step creat file form.register.php
code details bellow :
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="proc.register.php"> <table width="468" border="0" align="center"> <tr> <td width="139">Name</td> <td width="319"><input name="name" type="text" id="name" size="50" /></td> </tr> <tr> <td>Email</td> <td><input name="email" type="text" id="email" size="50" /></td> </tr> <tr> <td>Address</td> <td><textarea name="address" id="address" cols="45" rows="5"></textarea></td> </tr> <tr> <td>Phone</td> <td><input name="phone" type="text" id="phone" size="30" /></td> </tr> <tr> <td>Zipcode</td> <td><input type="text" name="zipcode" id="zipcode" /></td> </tr> <tr> <td>&nbsp;</td> <td><input type="submit" name="button" id="button" value="Submit" /></td> </tr> </table> </form> </body> </html>

Php code to store data using the following script and name the file proc.register.php details code bellow :
  <?php include "config.php"; $name = $_POST['name']; $email = $_POST['email']; $address = $_POST['address']; $phone = $_POST['phone']; $zipcode = $_POST['zipcode']; $savedata = mysql_query("INSERT INTO register (name,email,address,phone,zipcode,date) VALUES ('$name','$email','$address','$phone','$zipcode',NOW())"); $register = mysql_query("SELECT id_member FROM register ORDER BY date DESC LIMIT 1"); $r_register = mysql_fetch_array($register); header('location:form.register.php?id_member='.$r_register['id_member']); ?>
To make the registration data that has been stored as a PDF file, you need FPDF functions that I include in the download file at the end of this article. Rate this file name form.register_pdf.php
<?php session_start(); include ("config.php"); require_once("PDF/fpdf.php"); $id_member = $_GET['id_member']; $pdf=new FPDF(); $pdf->AddPage(); $pdf->SetAuthor('blizboxschool.com'); $pdf->SetTitle('Detail form register'); $pdf->setFont("Helvetica","",10); $registrasi = mysql_query("SELECT * FROM register WHERE id_member='$id_member'"); $rmember = mysql_fetch_array($registrasi); $id_member = $rmember['id_member']; $name = $rmember['name']; $address = $rmember['address']; $phone = $rmember['phone']; $zipcode = $rmember['zipcode']; $i=1; $fill = false; //area data anggota $pdf->Text(40, 70, 'ID member :'); $pdf->Text(80, 70, $id_member); $pdf->Text(40, 75, 'Name Of member :'); $pdf->Text(80, 75, $name); $pdf->Text(40, 80, 'Address :'); $pdf->Text(80, 80, $address); $pdf->Output('form.register_'.$id_member.'.pdf','F'); header('location:pdf_to_email.php?id_member='.$id_member); ?>
File form.register_pdf.php will form a file in your web directory and file that will be sent to the email using the code below to send email, file name pdf_to_email.php
<?php session_start(); include ("config.php"); $id_member = $_GET['id_member']; $mail = mysql_query("SELECT * FROM register WHERE id_member='$id_member'"); $rmail = mysql_fetch_array($mail); $mailto = $rmail['email']; /* +++++++++++++++++++++++++++++++++++++ + How to sending a PDF File Attachment + Through Email With PHP and MySQL +++++++++++++++++++++++++++++++++++++ By www.blizboxschool.com Author :Iblizkecil */ $fileatt = "Form_register_".$_GET['id_member'].'.pdf'; // Path to the file $fileatt_type = "application/pdf"; // File Type $fileatt_name = "Form_register_".$_GET['id_member'].'.pdf'; // Filename that will be used for the file as the attachment $email_from = "admin@localhost"; // Who the email is from $email_subject = "Registrasi form"; // The Subject of the email $email_message = "thank you for register at our website.<br>"; $email_message .= "here is details data registration file with pdf.<br>"; $email_message .= "<br><br><br>Best regard,<br>Admin blizboxschool"; // Message that the email has in it $email_to = $mailto; $headers = "From: admin@blizboxschool.com"; //$headers .= "Cc: admin@blizboxschool.com"; //$headers .= "Cc: admin@blizboxschool.com;admin@blizboxschool.com;admin@blizboxschool.com"; $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.0n" . "Content-Type: multipart/mixed;n" . " boundary="{$mime_boundary}""; $email_message .= "This is a multi-part message in MIME format.nn" . "--{$mime_boundary}n" . "Content-Type:text/html; charset="iso-8859-1"n" . "Content-Transfer-Encoding: 7bitnn" . $email_message .= "nn"; $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}n" . "Content-Type: {$fileatt_type};n" . " name="{$fileatt_name}"n" . //"Content-Disposition: attachment;n" . //" filename="{$fileatt_name}"n" . "Content-Transfer-Encoding: base64nn" . $data .= "nn" . "--{$mime_boundary}--n"; @mail($email_to, $email_subject, $email_message, $headers); ?> <script type="text/javascript"> alert("Data registration has been send to your email"); document.location="form.register.php"; </script>
PHP codes d above have been attempted utilizing yahoo and gmail accounts. If you don't mind transfer this code to your site, its dependent upon the mo and run paid or unhindered. The documents could be Downloaded Here. Trust it serves some useful purpose.
Keyword: send pdf php, php pdf attachments, email attachments pdf php, php email pdf, pdf php email.
reference : www.stackoverflow.com
If you have a question about how to apply and anything you need just leave a comment.

How to Sending a PDF File Attachment Through Email With PHP and MySQL Rating: 4.5 Diposkan Oleh: morellocyber

0 comments:

Post a Comment