Advertisement
Guest User

Untitled

a guest
Mar 10th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <?php
  2. require_once('phpmailer/class.phpmailer.php');
  3. define('GUSER', 'youtGmail@gmail.com); // GMail username
  4. define('GPWD', 'gmailPassword'); // GMail password
  5.  
  6. function smtpmailer($to, $from, $from_name, $subject, $body) {
  7. global $error;
  8. $mail = new PHPMailer(); // create a new object
  9. $mail->IsSMTP(); // enable SMTP
  10. $mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
  11. $mail->SMTPAuth = true; // authentication enabled
  12. $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
  13. $mail->Host = 'smtp.gmail.com';
  14. $mail->Port = 465;
  15. $mail->Username = GUSER;
  16. $mail->Password = GPWD;
  17. $mail->SetFrom($from, $from_name);
  18. $mail->Subject = $subject;
  19. $mail->Body = $body;
  20. $mail->AddAddress($to);
  21. if(!$mail->Send()) {
  22. $error = 'Mail error: '.$mail->ErrorInfo;
  23. return false;
  24. } else {
  25. $error = 'Message sent!';
  26. return true;
  27. }
  28. }
  29.  
  30. if(isset($_POST['submit'])) {
  31.  
  32.  
  33. if(trim($_POST['contactname']) == '') {
  34. $hasError = true;
  35. } else {
  36. $name = trim($_POST['contactname']);
  37. }
  38.  
  39.  
  40. if(trim($_POST['subject']) == '') {
  41. $hasError = true;
  42. } else {
  43. $subject = trim($_POST['subject']);
  44. }
  45.  
  46.  
  47. if(trim($_POST['email']) == '') {
  48. $hasError = true;
  49. } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,4}$", trim($_POST['email']))) {
  50. $hasError = true;
  51. } else {
  52. $email = trim($_POST['email']);
  53. }
  54.  
  55.  
  56. if(trim($_POST['message']) == '') {
  57. $hasError = true;
  58. } else {
  59. if(function_exists('stripslashes')) {
  60. $comments = stripslashes(trim($_POST['message']));
  61. } else {
  62. $comments = trim($_POST['message']);
  63. }
  64. }
  65.  
  66.  
  67. if(!isset($hasError)) {
  68.  
  69. $emailTo = 'your@email.com';
  70. smtpmailer($emailTo, $email, 'Company', $name, $subject, $comments);
  71. $emailSent = true;
  72.  
  73. }
  74. }
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement