Advertisement
Guest User

Untitled

a guest
May 25th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2.  
  3. require_once('config.php');
  4. require("class.PHPMailer.php"); //inclui o PHPMailer aqui
  5.  
  6. // Sender Info
  7. $name = trim($_POST['name']);
  8. $email = trim($_POST['email']);
  9. $message = trim($_POST['message']);
  10. $err = "";
  11.  
  12. // Check Info
  13. $pattern = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$^";
  14. if (!preg_match_all($pattern, $email, $out)) {
  15.     $err = MSG_INVALID_EMAIL; // Invalid email
  16. }
  17. if (!$email) {
  18.     $err = MSG_INVALID_EMAIL; // No Email
  19. }
  20. if (!$message) {
  21.     $err = MSG_INVALID_MESSAGE; // No Message
  22. }
  23. if (!$name) {
  24.     $err = MSG_INVALID_NAME; // No name
  25. }
  26.  
  27. if (!$err) {
  28.  
  29.     //send the email
  30.     $mail = new PHPMailer();
  31.  
  32.     $mail->IsSMTP();                                      // set mailer to use SMTP
  33.     $mail->Host = "mail.example.com;mail2.example.com";  // specify main and backup server
  34.     $mail->SMTPAuth = true;     // turn on SMTP authentication
  35.     $mail->Username = "jswan";  // SMTP username
  36.     $mail->Password = "secret"; // SMTP password
  37.  
  38.     $mail->From = $email;
  39.     $mail->FromName = $name;
  40.     $mail->AddAddress(TO_EMAIL);
  41.     $mail->AddReplyTo($email, $name);
  42.  
  43.     $mail->Subject = SUBJECT;
  44.     $mail->Body    = $message;
  45.  
  46.     $sent = $mail->Send()
  47.  
  48.     if ($sent) {
  49.         // If the message is sent successfully print
  50.         echo "SEND";
  51.     } else {
  52.         // Display Error Message
  53.         echo MSG_SEND_ERROR;
  54.     }
  55. } else {
  56.     echo $err; // Display Error Message
  57. }
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement