Advertisement
Guest User

Untitled

a guest
Oct 8th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.01 KB | None | 0 0
  1. <?php
  2. header("Content-Type: text/html; charset=utf-8");
  3. ini_set('display_errors', 1);
  4. ini_set('error_reporting', E_ALL);
  5.  
  6. echo 'sendmail<br>';
  7. echo 'Текущая версия PHP: ' . phpversion().'<br>';
  8.  
  9.  
  10. use PHPMailer\PHPMailer\PHPMailer;
  11.  
  12.  
  13. require __DIR__ .'/PHPMailer/src/Exception.php';
  14. require __DIR__ .'/PHPMailer/src/PHPMailer.php';
  15. require __DIR__ .'/PHPMailer/src/SMTP.php';
  16.  
  17.  
  18. //Create a new PHPMailer instance
  19. $mail = new PHPMailer;
  20. //Tell PHPMailer to use SMTP
  21. $mail->isSMTP();
  22. //Enable SMTP debugging
  23. // 0 = off (for production use)
  24. // 1 = client messages
  25. // 2 = client and server messages
  26. $mail->SMTPDebug = 2;
  27. //Set the hostname of the mail server
  28. $mail->Host = 'smtp.gmail.com';
  29. // use
  30. // $mail->Host = gethostbyname('smtp.gmail.com');
  31. // if your network does not support SMTP over IPv6
  32. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  33. $mail->Port = 587;
  34. //Set the encryption system to use - ssl (deprecated) or tls
  35. $mail->SMTPSecure = 'tls';
  36. //Whether to use SMTP authentication
  37. $mail->SMTPAuth = true;
  38. //Username to use for SMTP authentication - use full email address for gmail
  39. $mail->Username = "******@gmail.com";
  40. //Password to use for SMTP authentication
  41. $mail->Password = "*******";
  42. //Set who the message is to be sent from
  43. $mail->setFrom('****@gmail.com', 'First Last');
  44. //Set an alternative reply-to address
  45. $mail->addReplyTo('****@mail.ru', 'First Last');
  46. //Set who the message is to be sent to
  47. $mail->addAddress('****@mail.ru', 'John Doe');
  48. //Set the subject line
  49. $mail->Subject = 'PHPMailer GMail SMTP test';
  50. //Replace the plain text body with one created manually
  51. $mail->AltBody = 'This is a plain-text message body';
  52. //send the message, check for errors
  53. if (!$mail->send()) {
  54.     echo "Mailer Error: " . $mail->ErrorInfo;
  55. } else {
  56.    
  57.     echo "Message sent!";
  58.     //Section 2: IMAP
  59.     //Uncomment these to save your message in the 'Sent Mail' folder.
  60.     #if (save_mail($mail)) {
  61.    #    echo "Message saved!";
  62.    #}
  63. }
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement