Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Felipe
  5. * Date: 29/07/2016
  6. * Time: 07:41
  7. */
  8. //SMTP needs accurate times, and the PHP time zone MUST be set
  9. //This should be done in your php.ini, but this is how to do it if you don't have access to that
  10. date_default_timezone_set('Etc/UTC');
  11.  
  12. require '/lib/PHPMailerAutoload.php';
  13.  
  14. //Create a new PHPMailer instance
  15. $mail = new PHPMailer;
  16. //Tell PHPMailer to use SMTP
  17. $mail->isSMTP();
  18. //Enable SMTP debugging
  19. // 0 = off (for production use)
  20. // 1 = client messages
  21. // 2 = client and server messages
  22. $mail->SMTPDebug = 2;
  23. //Ask for HTML-friendly debug output
  24. $mail->Debugoutput = 'html';
  25. //Set the hostname of the mail server
  26. $mail->Host = "mail.example.com";
  27. //Set the SMTP port number - likely to be 25, 465 or 587
  28. $mail->Port = 25;
  29. //Whether to use SMTP authentication
  30. $mail->SMTPAuth = true;
  31. //Username to use for SMTP authentication
  32. $mail->Username = "yourname@example.com";
  33. //Password to use for SMTP authentication
  34. $mail->Password = "yourpassword";
  35. //Set who the message is to be sent from
  36. $mail->setFrom('from@example.com', 'First Last');
  37. //Set an alternative reply-to address
  38. $mail->addReplyTo('replyto@example.com', 'First Last');
  39. //Set who the message is to be sent to
  40. $mail->addAddress('whoto@example.com', 'John Doe');
  41. //Set the subject line
  42. $mail->Subject = 'PHPMailer SMTP test';
  43. //Read an HTML message body from an external file, convert referenced images to embedded,
  44. //convert HTML into a basic plain-text alternative body
  45. $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  46. //Replace the plain text body with one created manually
  47. $mail->AltBody = 'This is a plain-text message body';
  48. //Attach an image file
  49. $mail->addAttachment('images/phpmailer_mini.png');
  50.  
  51.  
  52. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  53. $errors = array();
  54. $headers = "From: " . "noreply@colourtone-masterbatch.co.uk" . "\r\n";
  55. $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  56. $headers .= "MIME-Version: 1.0\r\n";
  57. $firstname = (isset($_POST['firstname']) && ctype_alpha($_POST['firstname'])) ? $_POST['firstname'] : $errors[] = "Invalid First Name";
  58. $secondname = (isset($_POST['secondname']) && ctype_alpha($_POST['secondname'])) ? $_POST['secondname'] : $errors[] = "Invalid Second Name";
  59. $job = (isset($_POST['job'])) ? $_POST['job'] : $errors[] = "Invalid Job";
  60. $address1 = (isset($_POST['address1'])) ? $_POST['address1'] : $errors[] = "Invalid Address 1";
  61. $address2 = (isset($_POST['address2'])) ? $_POST['address2'] : $errors[] = "Invalid Address 2";
  62. $phone = (isset($_POST['phone'])) ? $_POST['phone'] : $errors[] = "Invalid Phone";
  63.  
  64. $message = "<html><body>";
  65. $message .= "<p>
  66. A visitor to the Vynacol website has requested a brochure! Their recorded details are:<br><br>
  67.  
  68. First Name: $firstname<br>
  69. Second Name: $secondname<br>
  70. Address Line 1: $address1<br>
  71. Contact Number: $phone<br>
  72. </p>";
  73. $message .= "</body></html>";
  74. if(empty($errors)) {
  75. if ($mail->send())
  76. $messages["success"] = "eMail sent!";
  77. else
  78. $messages["error"][] = "Something went wrong. Please contact site administrator." . $mail->ErrorInfo;;
  79. } else {
  80. $messages["error"] = $errors;
  81. }
  82.  
  83. // Print the JSON!
  84. print(json_encode($messages));
  85.  
  86. }
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement