Advertisement
Guest User

Untitled

a guest
Aug 27th, 2017
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. <?php
  2. $pesan = "";
  3. if (isset($_POST['submit'])) {
  4. require 'phpmailer/PHPMailerAutoload.php';
  5.  
  6. function sendemail($to, $subject, $body, $attachment){
  7. $mail = new PHPMailer();
  8. $mail->isSMTP();
  9. $mail->Host = 'smtp.office365.com';
  10. $mail->SMTPAuth = true;
  11. $mail->Username = 'test@gmail.com';
  12. $mail->Password = '123456';
  13. $mail->SMTPSecure = 'auto';
  14. $mail->Port = 587;
  15.  
  16. $mail->setFrom('test@gmail.com', 'admin');
  17. $mail->addAddress($to);
  18. $mail->addAttachment($attachment);
  19. $mail->Body = $body;
  20. $mail->isHTML(false);
  21.  
  22. return $mail->send();
  23. }
  24.  
  25. $to = $_POST['email'];
  26. $subjects = $_POST['subject'];
  27. $body = $_POST['body'];
  28. //$attachment = $_FILES['attachment'];
  29.  
  30. $file = "attachment/" . basename($_FILES['attachment']['name']);
  31.  
  32.  
  33. if (move_uploaded_file($_FILES['attachment']['tmp_name'], $file)) {
  34. if (sendemail($to, $subjects, $body, $file))
  35. $msg = "email was sent";
  36. else
  37. $msg = "failed to send;
  38. } else
  39. $msg = "please try again";
  40. }
  41.  
  42. ?>
  43.  
  44.  
  45.  
  46. <!DOCTYPE html>
  47. <html lang="en">
  48. <head>
  49. <meta charset="utf-8">
  50. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  51. <meta name="viewport" content="width=device-width, initial-scale=1">
  52.  
  53. <title>form email</title>
  54.  
  55. <link href="css/bootstrap.min.css" rel="stylesheet">
  56. <link href="css/style.css" rel="stylesheet">
  57.  
  58. </head>
  59. <body>
  60.  
  61. <div class="container-fluid">
  62. <div class="row">
  63. <div class="col-md-8">
  64. <form role="form" method="post" action="index.php" enctype="multipart/form-data">
  65. <div class="form-group">
  66.  
  67. <label for="exampleInputEmail1">
  68. To email
  69. </label>
  70. <input type="email" name="email" class="form-control">
  71. </div>
  72. <div class="form-group">
  73.  
  74. <label>
  75. Subject
  76. </label>
  77. <input type="text" name="subject" class="form-control">
  78. </div>
  79. <div class="form-group">
  80.  
  81. <label for="exampleInputFile">
  82. Attachment
  83. </label>
  84. <input type="file" name="attachment" id="exampleInputFile">
  85. </div>
  86.  
  87. <textarea name="body" rows="8" cols="122"></textarea>
  88.  
  89. </div><br>
  90. <div class="col-md-4">
  91.  
  92. <input type="submit" name="submit" class="btn btn-primary btn-lg active" value = "send email"><br><br>
  93.  
  94. </div>
  95. </form><br><br>
  96. <?php echo $msg; ?>
  97. </div>
  98. </div>
  99.  
  100. <script src="js/jquery.min.js"></script>
  101. <script src="js/bootstrap.min.js"></script>
  102. <script src="js/scripts.js"></script>
  103. </body>
  104. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement