Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'phpmailer_init', 'wpse8170_phpmailer_init' );
- function wpse8170_phpmailer_init( PHPMailer $phpmailer ) {
- $phpmailer->Host = 'your.smtp.server.here';
- $phpmailer->Port = 25; // could be different
- $phpmailer->Username = 'your_username@example.com'; // if required
- $phpmailer->Password = 'yourpassword'; // if required
- $phpmailer->SMTPAuth = true; // if required
- // $phpmailer->SMTPSecure = 'ssl'; // enable if required, 'tls' is another possible value
- $phpmailer->IsSMTP();
- }
- <?php
- defined( 'ABSPATH' ) OR exit;
- /**
- * Plugin Name: (WCM) PHPMailer SMTP Settings
- * Description: Enables SMTP servers, SSL/TSL authentication and SMTP settings.
- */
- add_action( 'phpmailer_init', 'phpmailerSMTP' );
- function phpmailerSMTP( $phpmailer )
- {
- # $phpmailer->IsSMTP();
- # $phpmailer->SMTPAuth = true; // Authentication
- # $phpmailer->Host = '';
- # $phpmailer->Username = '';
- # $phpmailer->Password = '';
- # $phpmailer->SMTPSecure = 'ssl'; // Enable if required - 'tls' is another possible value
- # $phpmailer->Port = 26; // SMTP Port - 26 is for GMail
- }
- <?php
- defined( 'ABSPATH' ) OR exit;
- /**
- * Plugin Name: (WCM) PHPMailer Exceptions & SMTP
- * Description: WordPress by default returns <code>FALSE</code> instead of an <code>Exception</code>. This plugin fixes that.
- */
- add_action( 'phpmailer_init', 'WCMphpmailerException' );
- function WCMphpmailerException( $phpmailer )
- {
- if ( ! defined( 'WP_DEBUG' ) OR ! WP_DEBUG )
- {
- $phpmailer->SMTPDebug = 0;
- $phpmailer->debug = 0;
- return;
- }
- if ( ! current_user_can( 'manage_options' ) )
- return;
- // Enable SMTP
- # $phpmailer->IsSMTP();
- $phpmailer->SMTPDebug = 2;
- $phpmailer->debug = 1;
- // Use `var_dump( $data )` to inspect stuff at the latest point and see
- // if something got changed in core. You should consider dumping it during the
- // `wp_mail` filter as well, so you get the original state for comparison.
- $data = apply_filters(
- 'wp_mail',
- compact( 'to', 'subject', 'message', 'headers', 'attachments' )
- );
- current_user_can( 'manage_options' )
- AND print htmlspecialchars( var_export( $phpmailer, true ) );
- $error = null;
- try
- {
- $sent = $phpmailer->Send();
- ! $sent AND $error = new WP_Error( 'phpmailerError', $sent->ErrorInfo );
- }
- catch ( phpmailerException $e )
- {
- $error = new WP_Error( 'phpmailerException', $e->errorMessage() );
- }
- catch ( Exception $e )
- {
- $error = new WP_Error( 'defaultException', $e->getMessage() );
- }
- if ( is_wp_error( $error ) )
- return printf(
- "%s: %s",
- $error->get_error_code(),
- $error->get_error_message()
- );
- }
- /**
- * Set the following constants in wp-config.php
- * These should be added somewhere BEFORE the
- * constant ABSPATH is defined.
- */
- define( 'SMTP_USER', 'user@example.com' ); // Username to use for SMTP authentication
- define( 'SMTP_PASS', 'smtp password' ); // Password to use for SMTP authentication
- define( 'SMTP_HOST', 'smtp.example.com' ); // The hostname of the mail server
- define( 'SMTP_FROM', 'website@example.com' ); // SMTP From email address
- define( 'SMTP_NAME', 'e.g Website Name' ); // SMTP From name
- define( 'SMTP_PORT', '25' ); // SMTP port number - likely to be 25, 465 or 587
- define( 'SMTP_SECURE', 'tls' ); // Encryption system to use - ssl or tls
- define( 'SMTP_AUTH', true ); // Use SMTP authentication (true|false)
- define( 'SMTP_DEBUG', 0 ); // for debugging purposes only set to 1 or 2
- /**
- * This function will connect wp_mail to your authenticated
- * SMTP server. Values are constants set in wp-config.php
- */
- add_action( 'phpmailer_init', 'send_smtp_email' );
- function send_smtp_email( $phpmailer ) {
- $phpmailer->isSMTP();
- $phpmailer->Host = SMTP_HOST;
- $phpmailer->SMTPAuth = SMTP_AUTH;
- $phpmailer->Port = SMTP_PORT;
- $phpmailer->Username = SMTP_USER;
- $phpmailer->Password = SMTP_PASS;
- $phpmailer->SMTPSecure = SMTP_SECURE;
- $phpmailer->From = SMTP_FROM;
- $phpmailer->FromName = SMTP_NAME;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement