Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. add_action( 'phpmailer_init', 'wpse8170_phpmailer_init' );
  2. function wpse8170_phpmailer_init( PHPMailer $phpmailer ) {
  3. $phpmailer->Host = 'your.smtp.server.here';
  4. $phpmailer->Port = 25; // could be different
  5. $phpmailer->Username = 'your_username@example.com'; // if required
  6. $phpmailer->Password = 'yourpassword'; // if required
  7. $phpmailer->SMTPAuth = true; // if required
  8. // $phpmailer->SMTPSecure = 'ssl'; // enable if required, 'tls' is another possible value
  9.  
  10. $phpmailer->IsSMTP();
  11. }
  12.  
  13. <?php
  14. defined( 'ABSPATH' ) OR exit;
  15. /**
  16. * Plugin Name: (WCM) PHPMailer SMTP Settings
  17. * Description: Enables SMTP servers, SSL/TSL authentication and SMTP settings.
  18. */
  19.  
  20. add_action( 'phpmailer_init', 'phpmailerSMTP' );
  21. function phpmailerSMTP( $phpmailer )
  22. {
  23. # $phpmailer->IsSMTP();
  24. # $phpmailer->SMTPAuth = true; // Authentication
  25. # $phpmailer->Host = '';
  26. # $phpmailer->Username = '';
  27. # $phpmailer->Password = '';
  28. # $phpmailer->SMTPSecure = 'ssl'; // Enable if required - 'tls' is another possible value
  29. # $phpmailer->Port = 26; // SMTP Port - 26 is for GMail
  30. }
  31.  
  32. <?php
  33. defined( 'ABSPATH' ) OR exit;
  34. /**
  35. * Plugin Name: (WCM) PHPMailer Exceptions & SMTP
  36. * Description: WordPress by default returns <code>FALSE</code> instead of an <code>Exception</code>. This plugin fixes that.
  37. */
  38.  
  39. add_action( 'phpmailer_init', 'WCMphpmailerException' );
  40. function WCMphpmailerException( $phpmailer )
  41. {
  42. if ( ! defined( 'WP_DEBUG' ) OR ! WP_DEBUG )
  43. {
  44. $phpmailer->SMTPDebug = 0;
  45. $phpmailer->debug = 0;
  46. return;
  47. }
  48. if ( ! current_user_can( 'manage_options' ) )
  49. return;
  50.  
  51. // Enable SMTP
  52. # $phpmailer->IsSMTP();
  53. $phpmailer->SMTPDebug = 2;
  54. $phpmailer->debug = 1;
  55.  
  56. // Use `var_dump( $data )` to inspect stuff at the latest point and see
  57. // if something got changed in core. You should consider dumping it during the
  58. // `wp_mail` filter as well, so you get the original state for comparison.
  59. $data = apply_filters(
  60. 'wp_mail',
  61. compact( 'to', 'subject', 'message', 'headers', 'attachments' )
  62. );
  63.  
  64. current_user_can( 'manage_options' )
  65. AND print htmlspecialchars( var_export( $phpmailer, true ) );
  66.  
  67. $error = null;
  68. try
  69. {
  70. $sent = $phpmailer->Send();
  71. ! $sent AND $error = new WP_Error( 'phpmailerError', $sent->ErrorInfo );
  72. }
  73. catch ( phpmailerException $e )
  74. {
  75. $error = new WP_Error( 'phpmailerException', $e->errorMessage() );
  76. }
  77. catch ( Exception $e )
  78. {
  79. $error = new WP_Error( 'defaultException', $e->getMessage() );
  80. }
  81.  
  82. if ( is_wp_error( $error ) )
  83. return printf(
  84. "%s: %s",
  85. $error->get_error_code(),
  86. $error->get_error_message()
  87. );
  88. }
  89.  
  90. /**
  91. * Set the following constants in wp-config.php
  92. * These should be added somewhere BEFORE the
  93. * constant ABSPATH is defined.
  94. */
  95. define( 'SMTP_USER', 'user@example.com' ); // Username to use for SMTP authentication
  96. define( 'SMTP_PASS', 'smtp password' ); // Password to use for SMTP authentication
  97. define( 'SMTP_HOST', 'smtp.example.com' ); // The hostname of the mail server
  98. define( 'SMTP_FROM', 'website@example.com' ); // SMTP From email address
  99. define( 'SMTP_NAME', 'e.g Website Name' ); // SMTP From name
  100. define( 'SMTP_PORT', '25' ); // SMTP port number - likely to be 25, 465 or 587
  101. define( 'SMTP_SECURE', 'tls' ); // Encryption system to use - ssl or tls
  102. define( 'SMTP_AUTH', true ); // Use SMTP authentication (true|false)
  103. define( 'SMTP_DEBUG', 0 ); // for debugging purposes only set to 1 or 2
  104.  
  105. /**
  106. * This function will connect wp_mail to your authenticated
  107. * SMTP server. Values are constants set in wp-config.php
  108. */
  109. add_action( 'phpmailer_init', 'send_smtp_email' );
  110. function send_smtp_email( $phpmailer ) {
  111. $phpmailer->isSMTP();
  112. $phpmailer->Host = SMTP_HOST;
  113. $phpmailer->SMTPAuth = SMTP_AUTH;
  114. $phpmailer->Port = SMTP_PORT;
  115. $phpmailer->Username = SMTP_USER;
  116. $phpmailer->Password = SMTP_PASS;
  117. $phpmailer->SMTPSecure = SMTP_SECURE;
  118. $phpmailer->From = SMTP_FROM;
  119. $phpmailer->FromName = SMTP_NAME;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement