-
-
Save tommcfarlin/9730973f0264ed016729 to your computer and use it in GitHub Desktop.
[WordPress] An example of how to specify a custom SMTP server when using the wp_mail function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Acme_Email { | |
public function __construct() { | |
add_action( 'phpmailer_init', array( $this, 'configure_smtp' ) ); | |
add_filter( 'wp_mail_content_type', create_function( '', 'return "text/html";' ) ); | |
add_filter( 'wp_mail_from', array( $this, 'from_email' ) ); | |
add_filter( 'wp_mail_from_name', array( $this, 'from_name' ) ); | |
} | |
/** | |
* @param string $message The HTML document to send as the message. | |
*/ | |
public function send( $message ) { | |
wp_mail( 'everyone@acme.com', 'Your Weekly Newsletter', $message ); | |
} | |
/** | |
* @return string The email address from which the newsletter is being sent. | |
*/ | |
public function from_email() { | |
return 'newsletter@tubular.com'; | |
} | |
/** | |
* @return string The name from which the newsletter is being sent. | |
*/ | |
public function from_name() { | |
return "Your Bodacious Newsletter"; | |
} | |
/** | |
* @param PHPMailer $phpmailer A reference to the current instance of PHP Mailer | |
*/ | |
private function configure_smtp( $phpmailer ){ | |
$phpmailer->isSMTP(); | |
$phpmailer->Host = 'smtp.acme-server.com'; | |
$phpmailer->SMTPAuth = TRUE; | |
$phpmailer->Port = 25; | |
$phpmailer->Username = 'server@acme.com'; | |
$phpmailer->Password = 'acme-acne'; | |
$phpmailer->SMTPSecure = FALSE; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Acme_Email { | |
public function __construct() { | |
add_action( 'phpmailer_init', array( $this, 'configure_smtp' ) ); | |
add_filter( 'wp_mail_content_type', create_function( '', 'return "text/html";' ) ); | |
add_filter( 'wp_mail_from', array( $this, 'from_email' ) ); | |
add_filter( 'wp_mail_from_name', array( $this, 'from_name' ) ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @return string The email address from which the newsletter is being sent. | |
*/ | |
public function from_email() { | |
return 'newsletter@tubular.com'; | |
} | |
/** | |
* @return string The name from which the newsletter is being sent. | |
*/ | |
public function from_name() { | |
return "Your Bodacious Newsletter"; | |
} | |
/** | |
* @param PHPMailer $phpmailer A reference to the current instance of PHP Mailer | |
*/ | |
private function configure_smtp( $phpmailer ){ | |
$phpmailer->isSMTP(); | |
$phpmailer->Host = 'smtp.acme-server.com'; | |
$phpmailer->SMTPAuth = TRUE; | |
$phpmailer->Port = 25; | |
$phpmailer->Username = 'server@acme.com'; | |
$phpmailer->Password = 'acme-acne'; | |
$phpmailer->SMTPSecure = FALSE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment