Learning & Integrating web technology and code help directory

How to use PHP & Upload,Zip file and Send Email Attachment

No comments
How to use PHP & Upload,Zip file and Send Email Attachment This is Learn / tutorial php programming how to using  PHP Upload,Zip file and Send Email Attachment
ShotDev Focus:
- PHP & Upload,Zip file and Send Email Attachment.
Example
php_zip_mail1.php
  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <form action="php_zip_mail2.php" method="post" enctype="multipart/form-data" name="frmMain">  
  7. <table width="343" border="1">  
  8. <tr>  
  9. <td>To</td>  
  10. <td><input name="txtTo" type="text" ></td>  
  11. </tr>  
  12. <tr>  
  13. <td>Subject</td>  
  14. <td><input name="txtSubject" type="text"></td>  
  15. </tr>  
  16. <tr>  
  17. <td>Description</td>  
  18. <td><textarea name="txtDescription" cols="30" rows="4"></textarea></td>  
  19. </tr>  
  20. <tr>  
  21. <td>Form Name</td>  
  22. <td><input name="txtFormName" type="text"></td>  
  23. </tr>  
  24. <tr>  
  25. <tr>  
  26. <td>Form Email</td>  
  27. <td><input name="txtFormEmail" type="text"></td>  
  28. </tr>  
  29. <tr>  
  30. <td>Attachment</td>  
  31. <td>  
  32. <input name="fileAttach[]" type="file"><br>  
  33. <input name="fileAttach[]" type="file"><br>  
  34. <input name="fileAttach[]" type="file"><br>  
  35. <input name="fileAttach[]" type="file"><br>  
  36. <input name="fileAttach[]" type="file"><br>  
  37. <input name="fileAttach[]" type="file"><br></td>  
  38. </tr>  
  39. <tr>  
  40. <td>&nbsp;</td>  
  41. <td><input type="submit" name="Submit" value="Send"></td>  
  42. </tr>  
  43. </table>  
  44. </form>  
  45. </body>  
  46. </html>  
php_zip_mail2.php
  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. $strTo = $_POST["txtTo"];  
  8. $strSubject = $_POST["txtSubject"];  
  9. $strMessage = nl2br($_POST["txtDescription"]);  
  10.   
  11. //*** Uniqid Session ***//  
  12. $strSid = md5(uniqid(time()));  
  13.   
  14. $strHeader = "";  
  15. $strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";  
  16.   
  17. $strHeader .= "MIME-Version: 1.0\n";  
  18. $strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";  
  19. $strHeader .= "This is a multi-part message in MIME format.\n";  
  20.   
  21. $strHeader .= "--".$strSid."\n";  
  22. $strHeader .= "Content-type: text/html; charset=windows-874\n"// or UTF-8 //  
  23. $strHeader .= "Content-Transfer-Encoding: 7bit\n\n";  
  24. $strHeader .= $strMessage."\n\n";  
  25.   
  26. //*** Zip Files ***//  
  27. require_once("dZip.inc.php");  
  28. $PathName = "myfile";  
  29. $ZipName = "myzip.zip";  
  30. $zip = new dZip($PathName."/".$ZipName); // New Class  
  31. for($i=0;$i<count($_FILES["fileAttach"]["name"]);$i++)  
  32. {  
  33. if($_FILES["fileAttach"]["name"][$i] != "")  
  34. {  
  35. $zip->addFile($_FILES["fileAttach"]["tmp_name"][$i],$_FILES["fileAttach"]["name"][$i]); // Source,Destination  
  36. }  
  37. }  
  38.   
  39. $zip->save();  
  40.   
  41. //*** Attachment ***//  
  42. if($ZipName != "")  
  43. {  
  44. $strFilesName = $ZipName;  
  45. $strContent = chunk_split(base64_encode(file_get_contents($PathName."/".$ZipName)));  
  46. $strHeader .= "--".$strSid."\n";  
  47. $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";  
  48. $strHeader .= "Content-Transfer-Encoding: base64\n";  
  49. $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";  
  50. $strHeader .= $strContent."\n\n";  
  51. }  
  52.   
  53. $flgSend = @mail($strTo,$strSubject,null,$strHeader);  // @ = No Show Error //  
  54. if($flgSend)  
  55. {  
  56. echo "Email send completed.";  
  57. }  
  58. else  
  59. {  
  60. echo "Cannot send mail.";  
  61. }  
  62. ?>  
  63. </body>  
  64. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP Upload,Zip file and Send Email Attachment

No comments :

Post a Comment