Advertisement
Guest User

Untitled

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