Advertisement
Guest User

Untitled

a guest
Oct 31st, 2017
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. <?php
  2. $msg = "";
  3. use PHPMailer\PHPMailer\PHPMailer;
  4. include_once "PHPMailer/PHPMailer.php";
  5. include_once "PHPMailer/Exception.php";
  6. include_once "PHPMailer/SMTP.php";
  7.  
  8. if (isset($_POST['submit'])) {
  9. $subject = $_POST['subject'];
  10. $email = $_POST['email'];
  11. $message = $_POST['message'];
  12.  
  13. if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != "") {
  14. $file = "attachment/" . basename($_FILES['attachment']['name']);
  15. move_uploaded_file($_FILES['attachment']['tmp_name'], $file);
  16. } else
  17. $file = "";
  18.  
  19. $mail = new PHPMailer();
  20.  
  21. //if we want to send via SMTP
  22. $mail->Host = "smtp.gmail.com";
  23. //$mail->isSMTP();
  24. $mail->SMTPAuth = true;
  25. $mail->Username = "factuurtest1@gmail.com";
  26. $mail->Password = "tempwachtwoord";
  27. $mail->SMTPSecure = "ssl"; //TLS
  28. $mail->Port = 465; //587
  29.  
  30. $mail->addAddress('factuurtest1@gmail.com');
  31. $mail->setFrom($email);
  32. $mail->Subject = $subject;
  33. $mail->isHTML(true);
  34. $mail->Body = $message;
  35. $mail->addAttachment($file);
  36.  
  37. if ($mail->send())
  38. $msg = "Your email has been sent, thank you!";
  39. else
  40. $msg = $mail->ErrorInfo;
  41.  
  42. //unlink($file);
  43. }
  44. ?>
  45. <!doctype html>
  46. <html lang="en">
  47. <head>
  48. <meta charset="UTF-8">
  49. <meta name="viewport"
  50. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  51. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  52. <title>Contact Form</title>
  53. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
  54. </head>
  55. <body>
  56. <div class="container" style="margin-top: 100px">
  57. <div class="row justify-content-center">
  58. <div class="col-md-6 col-md-offset-3" align="center">
  59. <img src="images/logo.png"><br><br>
  60.  
  61. <?php if ($msg != "") echo "$msg<br><br>"; ?>
  62.  
  63. <form method="post" action="sendemail.php" enctype="multipart/form-data">
  64. <input class="form-control" name="subject" placeholder="Subject..."><br>
  65. <input class="form-control" name="email" type="email" placeholder="Email..."><br>
  66. <textarea placeholder="Message..." class="form-control" name="message"></textarea><br>
  67. <input class="form-control" type="file" name="attachment"><br>
  68. <input class="btn btn-primary" name="submit" type="submit" value="Send Email">
  69. </form>
  70. </div>
  71. </div>
  72. </div>
  73. </body>
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement