Initial commit
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\AmazonSES;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* AmazonSES Options constructor.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/aws.svg',
|
||||
'slug' => 'amazonses',
|
||||
'title' => esc_html__( 'Amazon SES', 'wp-mail-smtp' ),
|
||||
'disabled' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
?>
|
||||
|
||||
<p>
|
||||
<?php esc_html_e( 'We\'re sorry, the Amazon SES mailer is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
148
wp-content/plugins/wp-mail-smtp/src/Providers/AuthAbstract.php
Normal file
148
wp-content/plugins/wp-mail-smtp/src/Providers/AuthAbstract.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\Options as PluginOptions;
|
||||
|
||||
/**
|
||||
* Class AuthAbstract.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class AuthAbstract implements AuthInterface {
|
||||
|
||||
/**
|
||||
* Mailer DB options.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mailer_slug = '';
|
||||
|
||||
/**
|
||||
* Key for a stored unique state value.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $state_key = 'wp_mail_smtp_provider_client_state';
|
||||
|
||||
/**
|
||||
* Use the composer autoloader to include the auth library and all dependencies.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function include_vendor_lib() {
|
||||
|
||||
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url, that users will be redirected back to finish the OAuth process.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_plugin_auth_url() {
|
||||
|
||||
return add_query_arg( 'tab', 'auth', wp_mail_smtp()->get_admin()->get_admin_page_url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update auth code in our DB.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $code
|
||||
*/
|
||||
protected function update_auth_code( $code ) {
|
||||
|
||||
$options = new PluginOptions();
|
||||
$all = $options->get_all();
|
||||
|
||||
// To save in DB.
|
||||
$all[ $this->mailer_slug ]['auth_code'] = $code;
|
||||
|
||||
// To save in currently retrieved options array.
|
||||
$this->options['auth_code'] = $code;
|
||||
|
||||
$options->set( $all );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update access token in our DB.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param mixed $token
|
||||
*/
|
||||
protected function update_access_token( $token ) {
|
||||
|
||||
$options = new PluginOptions();
|
||||
$all = $options->get_all();
|
||||
|
||||
// To save in DB.
|
||||
$all[ $this->mailer_slug ]['access_token'] = $token;
|
||||
|
||||
// To save in currently retrieved options array.
|
||||
$this->options['access_token'] = $token;
|
||||
|
||||
$options->set( $all );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update refresh token in our DB.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param mixed $token
|
||||
*/
|
||||
protected function update_refresh_token( $token ) {
|
||||
|
||||
$options = new PluginOptions();
|
||||
$all = $options->get_all();
|
||||
|
||||
// To save in DB.
|
||||
$all[ $this->mailer_slug ]['refresh_token'] = $token;
|
||||
|
||||
// To save in currently retrieved options array.
|
||||
$this->options['refresh_token'] = $token;
|
||||
|
||||
$options->set( $all );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_clients_saved() {
|
||||
|
||||
return ! empty( $this->options['client_id'] ) && ! empty( $this->options['client_secret'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_auth_required() {
|
||||
|
||||
return empty( $this->options['access_token'] ) || empty( $this->options['refresh_token'] );
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
/**
|
||||
* Interface AuthInterface.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface AuthInterface {
|
||||
|
||||
/**
|
||||
* Whether user saved Client ID/App ID and Client Secret/App Password or not.
|
||||
* Both options are required.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_clients_saved();
|
||||
|
||||
/**
|
||||
* Whether we have an access and refresh tokens or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_auth_required();
|
||||
}
|
283
wp-content/plugins/wp-mail-smtp/src/Providers/Gmail/Auth.php
Normal file
283
wp-content/plugins/wp-mail-smtp/src/Providers/Gmail/Auth.php
Normal file
@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Gmail;
|
||||
|
||||
use WPMailSMTP\Admin\Area;
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\Options as PluginOptions;
|
||||
use WPMailSMTP\Providers\AuthAbstract;
|
||||
|
||||
/**
|
||||
* Class Auth to request access and refresh tokens.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Auth extends AuthAbstract {
|
||||
|
||||
/**
|
||||
* Auth constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$options = new PluginOptions();
|
||||
$this->mailer_slug = $options->get( 'mail', 'mailer' );
|
||||
|
||||
if ( $this->mailer_slug !== Options::SLUG ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->options = $options->get_group( $this->mailer_slug );
|
||||
|
||||
if ( $this->is_clients_saved() ) {
|
||||
|
||||
$this->include_vendor_lib();
|
||||
|
||||
$this->client = $this->get_client();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url, that users will be redirected back to finish the OAuth process.
|
||||
*
|
||||
* @since 1.5.2 Returned to the old, pre-1.5, structure of the link to preserve BC.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_plugin_auth_url() {
|
||||
|
||||
return add_query_arg(
|
||||
array(
|
||||
'page' => Area::SLUG,
|
||||
'tab' => 'auth',
|
||||
),
|
||||
admin_url( 'options-general.php' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init and get the Google Client object.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.5.0 Add ability to apply custom options to the client via a filter.
|
||||
*
|
||||
* @return \Google_Client
|
||||
*/
|
||||
public function get_client() {
|
||||
|
||||
// Doesn't load client twice + gives ability to overwrite.
|
||||
if ( ! empty( $this->client ) ) {
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
$this->include_vendor_lib();
|
||||
|
||||
$client = new \Google_Client(
|
||||
array(
|
||||
'client_id' => $this->options['client_id'],
|
||||
'client_secret' => $this->options['client_secret'],
|
||||
'redirect_uris' => array(
|
||||
self::get_plugin_auth_url(),
|
||||
),
|
||||
)
|
||||
);
|
||||
$client->setApplicationName( 'WP Mail SMTP v' . WPMS_PLUGIN_VER );
|
||||
$client->setAccessType( 'offline' );
|
||||
$client->setApprovalPrompt( 'force' );
|
||||
$client->setIncludeGrantedScopes( true );
|
||||
// We request only the sending capability, as it's what we only need to do.
|
||||
$client->setScopes( array( \Google_Service_Gmail::MAIL_GOOGLE_COM ) );
|
||||
$client->setRedirectUri( self::get_plugin_auth_url() );
|
||||
|
||||
// Apply custom options to the client.
|
||||
$client = apply_filters( 'wp_mail_smtp_providers_gmail_auth_get_client_custom_options', $client );
|
||||
|
||||
if (
|
||||
$this->is_auth_required() &&
|
||||
! empty( $this->options['auth_code'] )
|
||||
) {
|
||||
try {
|
||||
$creds = $client->fetchAccessTokenWithAuthCode( $this->options['auth_code'] );
|
||||
} catch ( \Exception $e ) {
|
||||
$creds['error'] = $e->getMessage();
|
||||
Debug::set(
|
||||
'Mailer: Gmail' . "\r\n" .
|
||||
$creds['error']
|
||||
);
|
||||
}
|
||||
|
||||
// Bail if we have an error.
|
||||
if ( ! empty( $creds['error'] ) ) {
|
||||
return $client;
|
||||
}
|
||||
|
||||
$this->update_access_token( $client->getAccessToken() );
|
||||
$this->update_refresh_token( $client->getRefreshToken() );
|
||||
}
|
||||
|
||||
if ( ! empty( $this->options['access_token'] ) ) {
|
||||
$client->setAccessToken( $this->options['access_token'] );
|
||||
}
|
||||
|
||||
// Refresh the token if it's expired.
|
||||
if ( $client->isAccessTokenExpired() ) {
|
||||
$refresh = $client->getRefreshToken();
|
||||
if ( empty( $refresh ) && isset( $this->options['refresh_token'] ) ) {
|
||||
$refresh = $this->options['refresh_token'];
|
||||
}
|
||||
|
||||
if ( ! empty( $refresh ) ) {
|
||||
try {
|
||||
$creds = $client->fetchAccessTokenWithRefreshToken( $refresh );
|
||||
} catch ( \Exception $e ) {
|
||||
$creds['error'] = $e->getMessage();
|
||||
Debug::set(
|
||||
'Mailer: Gmail' . "\r\n" .
|
||||
$e->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
// Bail if we have an error.
|
||||
if ( ! empty( $creds['error'] ) ) {
|
||||
return $client;
|
||||
}
|
||||
|
||||
$this->update_access_token( $client->getAccessToken() );
|
||||
$this->update_refresh_token( $client->getRefreshToken() );
|
||||
}
|
||||
}
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the auth code from the $_GET and save it.
|
||||
* Redirect user back to settings with an error message, if failed.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function process() {
|
||||
|
||||
if ( ! ( isset( $_GET['tab'] ) && $_GET['tab'] === 'auth' ) ) {
|
||||
wp_safe_redirect( wp_mail_smtp()->get_admin()->get_admin_page_url() );
|
||||
exit;
|
||||
}
|
||||
|
||||
// We can't process without saved client_id/secret.
|
||||
if ( ! $this->is_clients_saved() ) {
|
||||
Debug::set(
|
||||
esc_html__( 'There was an error while processing the Google authentication request. Please make sure that you have Client ID and Client Secret both valid and saved.', 'wp-mail-smtp' )
|
||||
);
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_no_clients',
|
||||
wp_mail_smtp()->get_admin()->get_admin_page_url()
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->include_vendor_lib();
|
||||
|
||||
$code = '';
|
||||
$scope = '';
|
||||
$error = '';
|
||||
|
||||
if ( isset( $_GET['error'] ) ) {
|
||||
$error = sanitize_key( $_GET['error'] );
|
||||
}
|
||||
|
||||
// In case of any error: display a message to a user.
|
||||
if ( ! empty( $error ) ) {
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_' . $error,
|
||||
wp_mail_smtp()->get_admin()->get_admin_page_url()
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( isset( $_GET['code'] ) ) {
|
||||
$code = $_GET['code'];
|
||||
}
|
||||
if ( isset( $_GET['scope'] ) ) {
|
||||
$scope = urldecode( $_GET['scope'] );
|
||||
}
|
||||
|
||||
// Let's try to get the access token.
|
||||
if (
|
||||
! empty( $code ) &&
|
||||
(
|
||||
$scope === \Google_Service_Gmail::MAIL_GOOGLE_COM . ' ' . \Google_Service_Gmail::GMAIL_SEND ||
|
||||
$scope === \Google_Service_Gmail::GMAIL_SEND . ' ' . \Google_Service_Gmail::MAIL_GOOGLE_COM ||
|
||||
$scope === \Google_Service_Gmail::GMAIL_SEND ||
|
||||
$scope === \Google_Service_Gmail::MAIL_GOOGLE_COM
|
||||
)
|
||||
) {
|
||||
// Save the auth code. So \Google_Client can reuse it to retrieve the access token.
|
||||
$this->update_auth_code( $code );
|
||||
} else {
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_no_code_scope',
|
||||
wp_mail_smtp()->get_admin()->get_admin_page_url()
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'success',
|
||||
'google_site_linked',
|
||||
wp_mail_smtp()->get_admin()->get_admin_page_url()
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the auth URL used to proceed to Provider to request access to send emails.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_auth_url() {
|
||||
|
||||
if (
|
||||
! empty( $this->client ) &&
|
||||
class_exists( 'Google_Client', false ) &&
|
||||
$this->client instanceof \Google_Client
|
||||
) {
|
||||
return filter_var( $this->client->createAuthUrl(), FILTER_SANITIZE_URL );
|
||||
}
|
||||
|
||||
return '#';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user information (like email etc) that is associated with the current connection.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_user_info() {
|
||||
|
||||
$gmail = new \Google_Service_Gmail( $this->get_client() );
|
||||
|
||||
try {
|
||||
$email = $gmail->users->getProfile( 'me' )->getEmailAddress();
|
||||
} catch ( \Exception $e ) {
|
||||
$email = '';
|
||||
}
|
||||
|
||||
return array( 'email' => $email );
|
||||
}
|
||||
}
|
222
wp-content/plugins/wp-mail-smtp/src/Providers/Gmail/Mailer.php
Normal file
222
wp-content/plugins/wp-mail-smtp/src/Providers/Gmail/Mailer.php
Normal file
@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Gmail;
|
||||
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\MailCatcher;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
* Not used for Gmail, as we are using its API.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://www.googleapis.com/upload/gmail/v1/users/{userId}/messages/send';
|
||||
|
||||
/**
|
||||
* Gmail message.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var \Google_Service_Gmail_Message
|
||||
*/
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function __construct( $phpmailer ) {
|
||||
parent::__construct( $phpmailer );
|
||||
|
||||
if ( ! $this->is_php_compatible() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-use the MailCatcher class methods and properties.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function process_phpmailer( $phpmailer ) {
|
||||
// Make sure that we have access to MailCatcher class methods.
|
||||
if (
|
||||
! $phpmailer instanceof MailCatcher &&
|
||||
! $phpmailer instanceof \PHPMailer
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->phpmailer = $phpmailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use Google API Services to send emails.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function send() {
|
||||
|
||||
// Include the Google library.
|
||||
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
|
||||
$auth = new Auth();
|
||||
$message = new \Google_Service_Gmail_Message();
|
||||
|
||||
/*
|
||||
* Right now Gmail doesn't allow to redefine From and Sender email headers.
|
||||
* It always uses the email address that was used to connect to its API.
|
||||
* With code below we are making sure that Email Log archive and single Email Log
|
||||
* have the save value for From email header.
|
||||
*/
|
||||
$gmail_creds = $auth->get_user_info();
|
||||
|
||||
if ( ! empty( $gmail_creds['email'] ) ) {
|
||||
$this->phpmailer->From = $gmail_creds['email'];
|
||||
$this->phpmailer->Sender = $gmail_creds['email'];
|
||||
}
|
||||
|
||||
// Get the raw MIME email using MailCatcher data.
|
||||
// We need here to make base64URL-safe string.
|
||||
$base64 = str_replace(
|
||||
array( '+', '/', '=' ),
|
||||
array( '-', '_', '' ),
|
||||
base64_encode( $this->phpmailer->getSentMIMEMessage() )
|
||||
);
|
||||
|
||||
$message->setRaw( $base64 );
|
||||
|
||||
$service = new \Google_Service_Gmail( $auth->get_client() );
|
||||
|
||||
try {
|
||||
$response = $service->users_messages->send( 'me', $message );
|
||||
|
||||
$this->process_response( $response );
|
||||
} catch ( \Exception $e ) {
|
||||
Debug::set(
|
||||
'Mailer: Gmail' . "\r\n" .
|
||||
$e->getMessage()
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save response from the API to use it later.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.5.0 Added action "wp_mail_smtp_providers_gmail_mailer_process_response" with $response.
|
||||
*
|
||||
* @param \Google_Service_Gmail_Message $response
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
$this->response = $response;
|
||||
|
||||
do_action( 'wp_mail_smtp_providers_gmail_mailer_process_response', $this->response, $this->phpmailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the email was sent.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_email_sent() {
|
||||
|
||||
$is_sent = false;
|
||||
|
||||
if ( method_exists( $this->response, 'getId' ) ) {
|
||||
$message_id = $this->response->getId();
|
||||
if ( ! empty( $message_id ) ) {
|
||||
$is_sent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear debug messages if email is successfully sent.
|
||||
if ( $is_sent ) {
|
||||
Debug::clear();
|
||||
}
|
||||
|
||||
return $is_sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$gmail_text = array();
|
||||
|
||||
$options = new \WPMailSMTP\Options();
|
||||
$gmail = $options->get_group( 'gmail' );
|
||||
$curl_ver = 'No';
|
||||
if ( function_exists( 'curl_version' ) ) {
|
||||
$curl = curl_version(); // phpcs:ignore
|
||||
$curl_ver = $curl['version'];
|
||||
}
|
||||
|
||||
$gmail_text[] = '<strong>Client ID/Secret:</strong> ' . ( ! empty( $gmail['client_id'] ) && ! empty( $gmail['client_secret'] ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>Auth Code:</strong> ' . ( ! empty( $gmail['auth_code'] ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>Access Token:</strong> ' . ( ! empty( $gmail['access_token'] ) ? 'Yes' : 'No' );
|
||||
|
||||
$gmail_text[] = '<br><strong>Server:</strong>';
|
||||
|
||||
$gmail_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) && defined( 'OPENSSL_VERSION_TEXT' ) ? OPENSSL_VERSION_TEXT : 'No' );
|
||||
$gmail_text[] = '<strong>PHP.allow_url_fopen:</strong> ' . ( ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>PHP.stream_socket_client():</strong> ' . ( function_exists( 'stream_socket_client' ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>PHP.fsockopen():</strong> ' . ( function_exists( 'fsockopen' ) ? 'Yes' : 'No' );
|
||||
$gmail_text[] = '<strong>PHP.curl_version():</strong> ' . $curl_ver; // phpcs:ignore
|
||||
if ( function_exists( 'apache_get_modules' ) ) {
|
||||
$modules = apache_get_modules();
|
||||
$gmail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'selinux_is_enabled' ) ) {
|
||||
$gmail_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'grsecurity_is_enabled' ) ) {
|
||||
$gmail_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
|
||||
return implode( '<br>', $gmail_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
if ( ! $this->is_php_compatible() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$auth = new Auth();
|
||||
|
||||
if (
|
||||
$auth->is_clients_saved() &&
|
||||
! $auth->is_auth_required()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
234
wp-content/plugins/wp-mail-smtp/src/Providers/Gmail/Options.php
Normal file
234
wp-content/plugins/wp-mail-smtp/src/Providers/Gmail/Options.php
Normal file
@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Gmail;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
const SLUG = 'gmail';
|
||||
|
||||
/**
|
||||
* Gmail Options constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/google.svg',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'Gmail', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses( /* translators: %s - URL to our Gmail doc. */
|
||||
__( 'Send emails using your Gmail or G Suite (formerly Google Apps) account, all while keeping your login credentials safe. Other Google SMTP methods require enabling less secure apps in your account and entering your password. However, this integration uses the Google API to improve email delivery issues while keeping your site secure.<br><br>Read our <a href="%s" target="_blank" rel="noopener noreferrer">Gmail documentation</a> to learn how to configure Gmail or G Suite.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://wpmailsmtp.com/docs/how-to-set-up-the-gmail-mailer-in-wp-mail-smtp/'
|
||||
),
|
||||
'notices' => array(
|
||||
'educational' => esc_html__( 'The Gmail mailer works well for sites that send low numbers of emails. However, Gmail\'s API has rate limitations and a number of additional restrictions that can lead to challenges during setup. If you expect to send a high volume of emails, or if you find that your web host is not compatible with the Gmail API restrictions, then we recommend considering a different mailer option.', 'wp-mail-smtp' ),
|
||||
),
|
||||
'php' => '5.5',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
// Do not display options if PHP version is not correct.
|
||||
if ( ! $this->is_php_correct() ) {
|
||||
$this->display_php_warning();
|
||||
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- Client ID -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_id"
|
||||
class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_id"><?php esc_html_e( 'Client ID', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_id]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'client_id' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'client_id' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_id" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Client Secret -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"
|
||||
class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"><?php esc_html_e( 'Client Secret', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'client_secret' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_GMAIL_CLIENT_SECRET' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_secret]"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'client_secret' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Authorized redirect URI -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"
|
||||
class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"><?php esc_html_e( 'Authorized redirect URI', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input type="text" readonly="readonly"
|
||||
value="<?php echo esc_attr( Auth::get_plugin_auth_url() ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"
|
||||
/>
|
||||
<button type="button" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-light-grey wp-mail-smtp-setting-copy"
|
||||
title="<?php esc_attr_e( 'Copy URL to clipboard', 'wp-mail-smtp' ); ?>"
|
||||
data-source_id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect">
|
||||
<span class="dashicons dashicons-admin-page"></span>
|
||||
</button>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Please copy this URL into the "Authorized redirect URIs" field of your Google web application.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Auth users button -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-authorize"
|
||||
class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label><?php esc_html_e( 'Authorization', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php $this->display_auth_setting_action(); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display either an "Allow..." or "Remove..." button.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
protected function display_auth_setting_action() {
|
||||
|
||||
// Do the processing on the fly, as having ajax here is too complicated.
|
||||
$this->process_provider_remove();
|
||||
|
||||
$auth = new Auth();
|
||||
?>
|
||||
|
||||
<?php if ( $auth->is_clients_saved() ) : ?>
|
||||
|
||||
<?php if ( $auth->is_auth_required() ) : ?>
|
||||
|
||||
<a href="<?php echo esc_url( $auth->get_auth_url() ); ?>" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange">
|
||||
<?php esc_html_e( 'Allow plugin to send emails using your Google account', 'wp-mail-smtp' ); ?>
|
||||
</a>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Click the button above to confirm authorization.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<a href="<?php echo esc_url( wp_nonce_url( wp_mail_smtp()->get_admin()->get_admin_page_url(), 'gmail_remove', 'gmail_remove_nonce' ) ); ?>#wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-authorize" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-red js-wp-mail-smtp-provider-remove">
|
||||
<?php esc_html_e( 'Remove Connection', 'wp-mail-smtp' ); ?>
|
||||
</a>
|
||||
<span class="connected-as">
|
||||
<?php
|
||||
$user = $auth->get_user_info();
|
||||
|
||||
if ( ! empty( $user['email'] ) ) {
|
||||
printf(
|
||||
/* translators: %s - email address, as received from Google API. */
|
||||
esc_html__( 'Connected as %s', 'wp-mail-smtp' ),
|
||||
'<code>' . esc_html( $user['email'] ) . '</code>'
|
||||
);
|
||||
}
|
||||
?>
|
||||
</span>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Removing the connection will give you an ability to redo the connection or link to another Google account.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<p class="inline-notice inline-error">
|
||||
<?php esc_html_e( 'You need to save settings with Client ID and Client Secret before you can proceed.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Provider connection.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public function process_provider_remove() {
|
||||
|
||||
if ( ! is_super_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
! isset( $_GET['gmail_remove_nonce'] ) ||
|
||||
! wp_verify_nonce( $_GET['gmail_remove_nonce'], 'gmail_remove' ) // phpcs:ignore
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$options = new \WPMailSMTP\Options();
|
||||
|
||||
if ( $options->get( 'mail', 'mailer' ) !== $this->get_slug() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$old_opt = $options->get_all();
|
||||
|
||||
foreach ( $old_opt[ $this->get_slug() ] as $key => $value ) {
|
||||
// Unset everything except Client ID and Secret.
|
||||
if ( ! in_array( $key, array( 'client_id', 'client_secret' ), true ) ) {
|
||||
unset( $old_opt[ $this->get_slug() ][ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
$options->set( $old_opt );
|
||||
}
|
||||
}
|
205
wp-content/plugins/wp-mail-smtp/src/Providers/Loader.php
Normal file
205
wp-content/plugins/wp-mail-smtp/src/Providers/Loader.php
Normal file
@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\MailCatcher;
|
||||
use WPMailSMTP\Options;
|
||||
|
||||
/**
|
||||
* Class Loader.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Loader {
|
||||
|
||||
/**
|
||||
* Key is the mailer option, value is the path to its classes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.6.0 Added Sendinblue.
|
||||
* @since 1.7.0 Added AmazonSES/Outlook as indication of the Pro mailers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $providers = array(
|
||||
'mail' => 'WPMailSMTP\Providers\Mail\\',
|
||||
'pepipostapi' => 'WPMailSMTP\Providers\PepipostAPI\\',
|
||||
'sendinblue' => 'WPMailSMTP\Providers\Sendinblue\\',
|
||||
'mailgun' => 'WPMailSMTP\Providers\Mailgun\\',
|
||||
'sendgrid' => 'WPMailSMTP\Providers\Sendgrid\\',
|
||||
'amazonses' => 'WPMailSMTP\Providers\AmazonSES\\',
|
||||
'gmail' => 'WPMailSMTP\Providers\Gmail\\',
|
||||
'outlook' => 'WPMailSMTP\Providers\Outlook\\',
|
||||
'smtp' => 'WPMailSMTP\Providers\SMTP\\',
|
||||
'pepipost' => 'WPMailSMTP\Providers\Pepipost\\',
|
||||
);
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var MailCatcher
|
||||
*/
|
||||
private $phpmailer;
|
||||
|
||||
/**
|
||||
* Get all the supported providers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_providers() {
|
||||
|
||||
if ( ! Options::init()->is_pepipost_active() ) {
|
||||
unset( $this->providers['pepipost'] );
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_loader_get_providers', $this->providers );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single provider FQN-path based on its name.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $provider
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_provider_path( $provider ) {
|
||||
|
||||
$provider = sanitize_key( $provider );
|
||||
|
||||
$providers = $this->get_providers();
|
||||
|
||||
return apply_filters(
|
||||
'wp_mail_smtp_providers_loader_get_provider_path',
|
||||
isset( $providers[ $provider ] ) ? $providers[ $provider ] : null,
|
||||
$provider
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the provider options, if exists.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $provider
|
||||
*
|
||||
* @return OptionsAbstract|null
|
||||
*/
|
||||
public function get_options( $provider ) {
|
||||
|
||||
return $this->get_entity( $provider, 'Options' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all options of all providers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return OptionsAbstract[]
|
||||
*/
|
||||
public function get_options_all() {
|
||||
|
||||
$options = array();
|
||||
|
||||
foreach ( $this->get_providers() as $provider => $path ) {
|
||||
|
||||
$option = $this->get_options( $provider );
|
||||
|
||||
if ( ! $option instanceof OptionsAbstract ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$slug = $option->get_slug();
|
||||
$title = $option->get_title();
|
||||
|
||||
if ( empty( $title ) || empty( $slug ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$options[] = $option;
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_loader_get_providers_all', $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the provider mailer, if exists.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $provider
|
||||
* @param MailCatcher $phpmailer
|
||||
*
|
||||
* @return MailerAbstract|null
|
||||
*/
|
||||
public function get_mailer( $provider, $phpmailer ) {
|
||||
|
||||
if (
|
||||
$phpmailer instanceof MailCatcher ||
|
||||
$phpmailer instanceof \PHPMailer
|
||||
) {
|
||||
$this->phpmailer = $phpmailer;
|
||||
}
|
||||
|
||||
return $this->get_entity( $provider, 'Mailer' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the provider auth, if exists.
|
||||
*
|
||||
* @param string $provider
|
||||
*
|
||||
* @return AuthAbstract|null
|
||||
*/
|
||||
public function get_auth( $provider ) {
|
||||
|
||||
return $this->get_entity( $provider, 'Auth' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a generic entity based on the request.
|
||||
*
|
||||
* @uses \ReflectionClass
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $provider
|
||||
* @param string $request
|
||||
*
|
||||
* @return OptionsAbstract|MailerAbstract|AuthAbstract|null
|
||||
*/
|
||||
protected function get_entity( $provider, $request ) {
|
||||
|
||||
$provider = sanitize_key( $provider );
|
||||
$request = sanitize_text_field( $request );
|
||||
$path = $this->get_provider_path( $provider );
|
||||
$entity = null;
|
||||
|
||||
if ( empty( $path ) ) {
|
||||
return $entity;
|
||||
}
|
||||
|
||||
try {
|
||||
$reflection = new \ReflectionClass( $path . $request );
|
||||
|
||||
if ( file_exists( $reflection->getFileName() ) ) {
|
||||
$class = $path . $request;
|
||||
if ( $this->phpmailer ) {
|
||||
$entity = new $class( $this->phpmailer );
|
||||
} else {
|
||||
$entity = new $class();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {
|
||||
Debug::set( "There was a problem while retrieving {$request} for {$provider}: {$e->getMessage()}" );
|
||||
$entity = null;
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_loader_get_entity', $entity, $provider, $request );
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mail;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer inherits everything from parent abstract class.
|
||||
* This file is required for a proper work of Loader and \ReflectionClass.
|
||||
*
|
||||
* @package WPMailSMTP\Providers\Mail
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$mail_text = array();
|
||||
|
||||
$mail_text[] = '<br><strong>Server:</strong>';
|
||||
|
||||
$disabled_functions = ini_get( 'disable_functions' );
|
||||
$disabled = (array) explode( ',', trim( $disabled_functions ) );
|
||||
|
||||
$mail_text[] = '<strong>PHP.mail():</strong> ' . ( in_array( 'mail', $disabled, true ) || ! function_exists( 'mail' ) ? 'No' : 'Yes' );
|
||||
if ( function_exists( 'apache_get_modules' ) ) {
|
||||
$modules = apache_get_modules();
|
||||
$mail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'selinux_is_enabled' ) ) {
|
||||
$mail_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'grsecurity_is_enabled' ) ) {
|
||||
$mail_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
|
||||
return implode( '<br>', $mail_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mail;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mail constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/php.svg',
|
||||
'slug' => 'mail',
|
||||
'title' => esc_html__( 'Default (none)', 'wp-mail-smtp' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php esc_html_e( 'You currently have the native WordPress option selected. Please select any other Mailer option above to continue the setup.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
417
wp-content/plugins/wp-mail-smtp/src/Providers/MailerAbstract.php
Normal file
417
wp-content/plugins/wp-mail-smtp/src/Providers/MailerAbstract.php
Normal file
@ -0,0 +1,417 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\Conflicts;
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\MailCatcher;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class MailerAbstract.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class MailerAbstract implements MailerInterface {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 200;
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var MailCatcher
|
||||
*/
|
||||
protected $phpmailer;
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mailer = '';
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = '';
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = array();
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $body = array();
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $response = array();
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param MailCatcher $phpmailer
|
||||
*/
|
||||
public function __construct( MailCatcher $phpmailer ) {
|
||||
|
||||
$this->options = new Options();
|
||||
$this->mailer = $this->options->get( 'mail', 'mailer' );
|
||||
|
||||
// Only non-SMTP mailers need URL and extra processing for PHPMailer class.
|
||||
if ( ! $this->options->is_mailer_smtp() && empty( $this->url ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->process_phpmailer( $phpmailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-use the MailCatcher class methods and properties.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param MailCatcher $phpmailer
|
||||
*/
|
||||
public function process_phpmailer( $phpmailer ) {
|
||||
|
||||
// Make sure that we have access to MailCatcher class methods.
|
||||
if (
|
||||
! $phpmailer instanceof MailCatcher &&
|
||||
! $phpmailer instanceof \PHPMailer
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->phpmailer = $phpmailer;
|
||||
|
||||
// Prevent working with those methods, as they are not needed for SMTP-like mailers.
|
||||
if ( $this->options->is_mailer_smtp() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_headers( $this->phpmailer->getCustomHeaders() );
|
||||
$this->set_from( $this->phpmailer->From, $this->phpmailer->FromName );
|
||||
$this->set_recipients(
|
||||
array(
|
||||
'to' => $this->phpmailer->getToAddresses(),
|
||||
'cc' => $this->phpmailer->getCcAddresses(),
|
||||
'bcc' => $this->phpmailer->getBccAddresses(),
|
||||
)
|
||||
);
|
||||
$this->set_subject( $this->phpmailer->Subject );
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$this->set_content( $this->phpmailer->Body );
|
||||
} else {
|
||||
$this->set_content(
|
||||
array(
|
||||
'text' => $this->phpmailer->AltBody,
|
||||
'html' => $this->phpmailer->Body,
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->set_return_path( $this->phpmailer->From );
|
||||
$this->set_reply_to( $this->phpmailer->getReplyToAddresses() );
|
||||
|
||||
/*
|
||||
* In some cases we will need to modify the internal structure
|
||||
* of the body content, if attachments are present.
|
||||
* So lets make this call the last one.
|
||||
*/
|
||||
$this->set_attachments( $this->phpmailer->getAttachments() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the email headers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $headers List of key=>value pairs.
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
if ( empty( $name ) || empty( $value ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->set_header( $name, $value );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set individual header key=>value pair for the email.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function set_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
|
||||
$this->headers[ $name ] = WP::sanitize_value( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email subject.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $subject
|
||||
*/
|
||||
public function set_subject( $subject ) {
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'subject' => $subject,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request params, that goes to the body of the HTTP request.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $param Key=>value of what should be sent to a 3rd party API.
|
||||
*
|
||||
* @internal param array $params
|
||||
*/
|
||||
protected function set_body_param( $param ) {
|
||||
|
||||
$this->body = Options::array_merge_recursive( $this->body, $param );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the email body.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_get_body', $this->body, $this->mailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the email headers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_headers() {
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_get_headers', $this->headers, $this->mailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the email.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.8.0 Added timeout for requests, same as max_execution_time.
|
||||
*/
|
||||
public function send() {
|
||||
|
||||
$timeout = (int) ini_get( 'max_execution_time' );
|
||||
|
||||
$params = Options::array_merge_recursive(
|
||||
$this->get_default_params(),
|
||||
array(
|
||||
'headers' => $this->get_headers(),
|
||||
'body' => $this->get_body(),
|
||||
'timeout' => $timeout ? $timeout : 30,
|
||||
)
|
||||
);
|
||||
|
||||
$response = wp_safe_remote_post( $this->url, $params );
|
||||
|
||||
$this->process_response( $response );
|
||||
}
|
||||
|
||||
/**
|
||||
* We might need to do something after the email was sent to the API.
|
||||
* In this method we preprocess the response from the API.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param mixed $response
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
// Save the error text.
|
||||
$errors = $response->get_error_messages();
|
||||
foreach ( $errors as $error ) {
|
||||
Debug::set( $error );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $response['body'] ) && WP::is_json( $response['body'] ) ) {
|
||||
$response['body'] = \json_decode( $response['body'] );
|
||||
}
|
||||
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default params, required for wp_safe_remote_post().
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_default_params() {
|
||||
|
||||
return apply_filters(
|
||||
'wp_mail_smtp_providers_mailer_get_default_params',
|
||||
array(
|
||||
'timeout' => 15,
|
||||
'httpversion' => '1.1',
|
||||
'blocking' => true,
|
||||
),
|
||||
$this->mailer
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the email is sent or not.
|
||||
* We basically check the response code from a request to provider.
|
||||
* Might not be 100% correct, not guarantees that email is delivered.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_email_sent() {
|
||||
|
||||
$is_sent = false;
|
||||
|
||||
if ( wp_remote_retrieve_response_code( $this->response ) === $this->email_sent_code ) {
|
||||
$is_sent = true;
|
||||
} else {
|
||||
$error = $this->get_response_error();
|
||||
|
||||
if ( ! empty( $error ) ) {
|
||||
// Add mailer to the beginning and save to display later.
|
||||
$message = 'Mailer: ' . esc_html( wp_mail_smtp()->get_providers()->get_options( $this->mailer )->get_title() ) . "\r\n";
|
||||
|
||||
$conflicts = new Conflicts();
|
||||
if ( $conflicts->is_detected() ) {
|
||||
$message .= 'Conflicts: ' . esc_html( $conflicts->get_conflict_name() ) . "\r\n";
|
||||
}
|
||||
|
||||
Debug::set( $message . $error );
|
||||
}
|
||||
}
|
||||
|
||||
// Clear debug messages if email is successfully sent.
|
||||
if ( $is_sent ) {
|
||||
Debug::clear();
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $is_sent, $this->mailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be overwritten when appropriate.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_response_error() {
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer supports the current PHP version or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_php_compatible() {
|
||||
|
||||
$options = wp_mail_smtp()->get_providers()->get_options( $this->mailer );
|
||||
|
||||
return version_compare( phpversion(), $options->get_php_version(), '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is relevant to SMTP and Pepipost.
|
||||
* All other custom mailers should override it with own information.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
global $phpmailer;
|
||||
|
||||
$smtp_text = array();
|
||||
|
||||
// Mail mailer has nothing to return.
|
||||
if ( $this->options->is_mailer_smtp() ) {
|
||||
// phpcs:disable
|
||||
$smtp_text[] = '<strong>ErrorInfo:</strong> ' . make_clickable( wp_strip_all_tags( $phpmailer->ErrorInfo ) );
|
||||
$smtp_text[] = '<strong>Host:</strong> ' . $phpmailer->Host;
|
||||
$smtp_text[] = '<strong>Port:</strong> ' . $phpmailer->Port;
|
||||
$smtp_text[] = '<strong>SMTPSecure:</strong> ' . Debug::pvar( $phpmailer->SMTPSecure );
|
||||
$smtp_text[] = '<strong>SMTPAutoTLS:</strong> ' . Debug::pvar( $phpmailer->SMTPAutoTLS );
|
||||
$smtp_text[] = '<strong>SMTPAuth:</strong> ' . Debug::pvar( $phpmailer->SMTPAuth );
|
||||
if ( ! empty( $phpmailer->SMTPOptions ) ) {
|
||||
$smtp_text[] = '<strong>SMTPOptions:</strong> <code>' . wp_json_encode( $phpmailer->SMTPOptions ) . '</code>';
|
||||
}
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
$smtp_text[] = '<br><strong>Server:</strong>';
|
||||
$smtp_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) && defined( 'OPENSSL_VERSION_TEXT' ) ? OPENSSL_VERSION_TEXT : 'No' );
|
||||
if ( function_exists( 'apache_get_modules' ) ) {
|
||||
$modules = apache_get_modules();
|
||||
$smtp_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'selinux_is_enabled' ) ) {
|
||||
$smtp_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
if ( function_exists( 'grsecurity_is_enabled' ) ) {
|
||||
$smtp_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
|
||||
}
|
||||
|
||||
return implode( '<br>', $smtp_text );
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
/**
|
||||
* Interface MailerInterface.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface MailerInterface {
|
||||
|
||||
/**
|
||||
* Send the email.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function send();
|
||||
|
||||
/**
|
||||
* Whether the email is sent or not.
|
||||
* We basically check the response code from a request to provider.
|
||||
* Might not be 100% correct, not guarantees that email is delivered.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_email_sent();
|
||||
|
||||
/**
|
||||
* Whether the mailer supports the current PHP version or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_php_compatible();
|
||||
|
||||
/**
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* @since 1.4.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete();
|
||||
|
||||
/**
|
||||
* Get the email body.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_body();
|
||||
|
||||
/**
|
||||
* Get the email headers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_headers();
|
||||
|
||||
/**
|
||||
* Get an array of all debug information relevant to the mailer.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_debug_info();
|
||||
|
||||
/**
|
||||
* Re-use the MailCatcher class methods and properties.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function process_phpmailer( $phpmailer );
|
||||
}
|
431
wp-content/plugins/wp-mail-smtp/src/Providers/Mailgun/Mailer.php
Normal file
431
wp-content/plugins/wp-mail-smtp/src/Providers/Mailgun/Mailer.php
Normal file
@ -0,0 +1,431 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mailgun;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API endpoint used for sites from all regions.
|
||||
*
|
||||
* @since 1.4.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const API_BASE_US = 'https://api.mailgun.net/v3/';
|
||||
|
||||
/**
|
||||
* API endpoint used for sites from EU region.
|
||||
*
|
||||
* @since 1.4.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const API_BASE_EU = 'https://api.eu.mailgun.net/v3/';
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = '';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct( $phpmailer ) {
|
||||
|
||||
// Default value should be defined before the parent class contructor fires.
|
||||
$this->url = self::API_BASE_US;
|
||||
|
||||
// We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
|
||||
parent::__construct( $phpmailer );
|
||||
|
||||
// We have a special API URL to query in case of EU region.
|
||||
if ( 'EU' === $this->options->get( $this->mailer, 'region' ) ) {
|
||||
$this->url = self::API_BASE_EU;
|
||||
}
|
||||
|
||||
/*
|
||||
* Append the url with a domain,
|
||||
* to avoid passing the domain name as a query parameter with all requests.
|
||||
*/
|
||||
$this->url .= sanitize_text_field( $this->options->get( $this->mailer, 'domain' ) . '/messages' );
|
||||
|
||||
$this->set_header( 'Authorization', 'Basic ' . base64_encode( 'api:' . $this->options->get( $this->mailer, 'api_key' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_from( $email, $name = '' ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'from' => $name . ' <' . $email . '>',
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'from' => $email,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_recipients( $recipients ) {
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$default = array( 'to', 'cc', 'bcc' );
|
||||
|
||||
foreach ( $recipients as $kind => $emails ) {
|
||||
if (
|
||||
! in_array( $kind, $default, true ) ||
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
$addr = isset( $email[0] ) ? $email[0] : false;
|
||||
$name = isset( $email[1] ) ? $email[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$data[] = $name . ' <' . $addr . '>';
|
||||
} else {
|
||||
$data[] = $addr;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
$kind => implode( ', ', $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
|
||||
$default = array( 'text', 'html' );
|
||||
|
||||
foreach ( $content as $type => $mail ) {
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $mail )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
$type => $mail,
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
||||
$type = 'html';
|
||||
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$type = 'text';
|
||||
}
|
||||
|
||||
if ( ! empty( $content ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
$type => $content,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are process for this mailer - they should be in body.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param array $headers
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message with a special prefix "h:".
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'h:' . $name => WP::sanitize_value( $value ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* It's the last one, so we can modify the whole body.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $attachments
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = '';
|
||||
$data = array();
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = false;
|
||||
|
||||
/*
|
||||
* We are not using WP_Filesystem API as we can't reliably work with it.
|
||||
* It is not always available, same as credentials for FTP.
|
||||
*/
|
||||
try {
|
||||
if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
|
||||
$file = file_get_contents( $attachment[0] );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {
|
||||
$file = false;
|
||||
}
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'content' => $file,
|
||||
'name' => $attachment[2],
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
|
||||
// First, generate a boundary for the multipart message.
|
||||
$boundary = base_convert( uniqid( 'boundary', true ), 10, 36 );
|
||||
|
||||
// Iterate through pre-built params and build a payload.
|
||||
foreach ( $this->body as $key => $value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $child_key => $child_value ) {
|
||||
$payload .= '--' . $boundary;
|
||||
$payload .= "\r\n";
|
||||
$payload .= 'Content-Disposition: form-data; name="' . $key . "\"\r\n\r\n";
|
||||
$payload .= $child_value;
|
||||
$payload .= "\r\n";
|
||||
}
|
||||
} else {
|
||||
$payload .= '--' . $boundary;
|
||||
$payload .= "\r\n";
|
||||
$payload .= 'Content-Disposition: form-data; name="' . $key . '"' . "\r\n\r\n";
|
||||
$payload .= $value;
|
||||
$payload .= "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Now iterate through our attachments, and add them too.
|
||||
foreach ( $data as $key => $attachment ) {
|
||||
$payload .= '--' . $boundary;
|
||||
$payload .= "\r\n";
|
||||
$payload .= 'Content-Disposition: form-data; name="attachment[' . $key . ']"; filename="' . $attachment['name'] . '"' . "\r\n\r\n";
|
||||
$payload .= $attachment['content'];
|
||||
$payload .= "\r\n";
|
||||
}
|
||||
|
||||
$payload .= '--' . $boundary . '--';
|
||||
|
||||
// Redefine the body the "dirty way".
|
||||
$this->body = $payload;
|
||||
|
||||
$this->set_header( 'Content-Type', 'multipart/form-data; boundary=' . $boundary );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_reply_to( $reply_to ) {
|
||||
|
||||
if ( empty( $reply_to ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $reply_to as $key => $emails ) {
|
||||
if (
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$addr = isset( $emails[0] ) ? $emails[0] : false;
|
||||
$name = isset( $emails[1] ) ? $emails[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$data[] = $name . ' <' . $addr . '>';
|
||||
} else {
|
||||
$data[] = $addr;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'h:Reply-To' => implode( ',', $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_return_path( $email ) {
|
||||
|
||||
if (
|
||||
$this->options->get( 'mail', 'return_path' ) !== true ||
|
||||
! filter_var( $email, FILTER_VALIDATE_EMAIL )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'sender' => $email,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Mailgun-specific response with a helpful error.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_response_error() {
|
||||
|
||||
$body = (array) wp_remote_retrieve_body( $this->response );
|
||||
|
||||
$error_text = array();
|
||||
|
||||
if ( ! empty( $body['message'] ) ) {
|
||||
if ( is_string( $body['message'] ) ) {
|
||||
$error_text[] = $body['message'];
|
||||
} else {
|
||||
$error_text[] = \json_encode( $body['message'] );
|
||||
}
|
||||
} elseif ( ! empty( $body[0] ) ) {
|
||||
if ( is_string( $body[0] ) ) {
|
||||
$error_text[] = $body[0];
|
||||
} else {
|
||||
$error_text[] = \json_encode( $body[0] );
|
||||
}
|
||||
}
|
||||
|
||||
return implode( '<br>', array_map( 'esc_textarea', $error_text ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$mg_text = array();
|
||||
|
||||
$options = new \WPMailSMTP\Options();
|
||||
$mailgun = $options->get_group( 'mailgun' );
|
||||
|
||||
$mg_text[] = '<strong>Api Key / Domain:</strong> ' . ( ! empty( $mailgun['api_key'] ) && ! empty( $mailgun['domain'] ) ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $mg_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->options->get_group( $this->mailer );
|
||||
|
||||
// API key is the only required option.
|
||||
if (
|
||||
! empty( $options['api_key'] ) &&
|
||||
! empty( $options['domain'] )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mailgun;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailgun constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/mailgun.svg',
|
||||
'slug' => 'mailgun',
|
||||
'title' => esc_html__( 'Mailgun', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
|
||||
__( '%1$sMailgun%2$s is one of the leading transactional email services trusted by over 150,000+ businesses. They provide 5,000 free emails per month for 3 months.<br><br>Read our %3$sMailgun documentation%4$s to learn how to configure Mailgun and improve your email deliverability.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'<a href="https://www.mailgun.com" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>',
|
||||
'<a href="https://wpmailsmtp.com/docs/how-to-set-up-the-mailgun-mailer-in-wp-mail-smtp/" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<!-- API Key -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'Private API Key', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_MAILGUN_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - API key link. */
|
||||
esc_html__( 'Follow this link to get an API Key from Mailgun: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.mailgun.com/app/account/security/api_keys" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get a Private API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Domain -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-domain" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-domain"><?php esc_html_e( 'Domain Name', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][domain]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'domain' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'domain' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-domain" spellcheck="false"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - Domain Name link. */
|
||||
esc_html__( 'Follow this link to get a Domain Name from Mailgun: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.mailgun.com/app/domains" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get a Domain Name', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Region -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-region" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-radio wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label><?php esc_html_e( 'Region', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-us">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-us"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][region]" value="US"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'region' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'US', $this->options->get( $this->get_slug(), 'region' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'US', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-eu">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-eu"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][region]" value="EU"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'region' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'EU', $this->options->get( $this->get_slug(), 'region' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'EU', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Define which endpoint you want to use for sending messages.', 'wp-mail-smtp' ); ?><br>
|
||||
<?php esc_html_e( 'If you are operating under EU laws, you may be required to use EU region.', 'wp-mail-smtp' ); ?>
|
||||
<?php
|
||||
printf(
|
||||
wp_kses(
|
||||
/* translators: %s - URL to Mailgun.com page. */
|
||||
__( '<a href="%s" rel="" target="_blank">More information</a> on Mailgun.com.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://www.mailgun.com/regions'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
@ -0,0 +1,477 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\Options;
|
||||
|
||||
/**
|
||||
* Abstract Class ProviderAbstract to contain common providers functionality.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class OptionsAbstract implements OptionsInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $logo_url = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $slug = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $title = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $description = '';
|
||||
/**
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $notices = array();
|
||||
/**
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $recommended = false;
|
||||
/**
|
||||
* @since 1.7.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $disabled = false;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $php = WPMS_PHP_VER;
|
||||
/**
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* ProviderAbstract constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( $params ) {
|
||||
|
||||
if (
|
||||
empty( $params['slug'] ) ||
|
||||
empty( $params['title'] )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->slug = sanitize_key( $params['slug'] );
|
||||
$this->title = sanitize_text_field( $params['title'] );
|
||||
|
||||
if ( ! empty( $params['description'] ) ) {
|
||||
$this->description = wp_kses_post( $params['description'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $params['notices'] ) ) {
|
||||
foreach ( (array) $params['notices'] as $key => $notice ) {
|
||||
$key = sanitize_key( $key );
|
||||
if ( empty( $key ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$notice = wp_kses(
|
||||
$notice,
|
||||
array(
|
||||
'br' => true,
|
||||
'strong' => true,
|
||||
'em' => true,
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'rel' => true,
|
||||
'target' => true,
|
||||
),
|
||||
)
|
||||
);
|
||||
if ( empty( $notice ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->notices[ $key ] = $notice;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $params['recommended'] ) ) {
|
||||
$this->recommended = (bool) $params['recommended'];
|
||||
}
|
||||
if ( isset( $params['disabled'] ) ) {
|
||||
$this->disabled = (bool) $params['disabled'];
|
||||
}
|
||||
|
||||
if ( ! empty( $params['php'] ) ) {
|
||||
$this->php = sanitize_text_field( $params['php'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $params['logo_url'] ) ) {
|
||||
$this->logo_url = esc_url_raw( $params['logo_url'] );
|
||||
}
|
||||
|
||||
$this->options = new Options();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_logo_url() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_logo_url', $this->logo_url, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_slug() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_slug', $this->slug, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_title() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_title', $this->title, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_description() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_description', $this->description, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Some mailers may display a notice above its options.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_notice( $type ) {
|
||||
|
||||
$type = sanitize_key( $type );
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_notice', isset( $this->notices[ $type ] ) ? $this->notices[ $type ] : '', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_php_version() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_php_version', $this->php, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<!-- SMTP Host -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-host" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-host"><?php esc_html_e( 'SMTP Host', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][host]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'host' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'host' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-host" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Encryption -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-encryption" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-radio wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="none"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'none', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'None', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="ssl"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'ssl', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'SSL', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="tls"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'tls', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'TLS', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'For most servers TLS is the recommended option. If your SMTP provider offers both SSL and TLS options, we recommend using TLS.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Port -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-number wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][port]" type="number"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'port' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'port' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="small-text" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PHPMailer SMTPAutoTLS -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-autotls" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) || 'tls' === $this->options->get( $this->get_slug(), 'encryption' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"><?php esc_html_e( 'Auto TLS', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls">
|
||||
<input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][autotls]" value="yes"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'autotls' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( true, (bool) $this->options->get( $this->get_slug(), 'autotls' ) ); ?>
|
||||
/>
|
||||
<span class="wp-mail-smtp-setting-toggle-switch"></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
|
||||
</label>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'By default TLS encryption is automatically used if the server supports it, which is recommended. In some cases, due to server misconfigurations, this can cause issues and may need to be disabled.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Authentication -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-auth" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth">
|
||||
<input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][auth]" value="yes"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'auth' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( true, (bool) $this->options->get( $this->get_slug(), 'auth' ) ); ?>
|
||||
/>
|
||||
<span class="wp-mail-smtp-setting-toggle-switch"></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Username -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-user" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user"><?php esc_html_e( 'SMTP Username', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][user]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'user' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'user' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user" spellcheck="false" autocomplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Password -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-pass" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-password wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"><?php esc_html_e( 'SMTP Password', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'pass' ) ) : ?>
|
||||
<input type="text" value="*************" disabled id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"/>
|
||||
|
||||
<?php $this->display_const_set_message( 'WPMS_SMTP_PASS' ); ?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - constant name: WPMS_SMTP_PASS. */
|
||||
esc_html__( 'To change the password you need to change the value of the constant there: %s', 'wp-mail-smtp' ),
|
||||
'<code>define( \'WPMS_SMTP_PASS\', \'your_old_password\' );</code>'
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %1$s - wp-config.php file, %2$s - WPMS_ON constant name. */
|
||||
esc_html__( 'If you want to disable the use of constants, find in %1$s file the constant %2$s and turn if off:', 'wp-mail-smtp' ),
|
||||
'<code>wp-config.php</code>',
|
||||
'<code>WPMS_ON</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<pre>
|
||||
define( 'WPMS_ON', false );
|
||||
</pre>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'All the defined constants will stop working and you will be able to change all the values on this page.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][pass]" type="password"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'pass' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass" spellcheck="false" autocomplete="new-password"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'The password is stored in plain text. We highly recommend you set up your password in your WordPress configuration file for improved security.', 'wp-mail-smtp' ); ?>
|
||||
<br>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - wp-config.php. */
|
||||
esc_html__( 'To do this add the lines below to your %s file:', 'wp-mail-smtp' ),
|
||||
'<code>wp-config.php</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<pre>
|
||||
define( 'WPMS_ON', true );
|
||||
define( 'WPMS_SMTP_PASS', 'your_password' );
|
||||
</pre>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this mailer is recommended or not.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_recommended() {
|
||||
|
||||
return (bool) apply_filters( 'wp_mail_smtp_providers_provider_is_recommended', $this->recommended, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this mailer is disabled or not.
|
||||
* Used for displaying Pro mailers inside Lite plugin.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_disabled() {
|
||||
|
||||
return (bool) apply_filters( 'wp_mail_smtp_providers_provider_is_disabled', $this->disabled, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we can use this provider based on the PHP version.
|
||||
* Valid for those, that use SDK.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_php_correct() {
|
||||
return version_compare( phpversion(), $this->php, '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a helpful message to those users, that are using an outdated version of PHP,
|
||||
* which is not supported by the currently selected Provider.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function display_php_warning() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %1$s - Provider name; %2$s - PHP version required by Provider; %3$s - current PHP version. */
|
||||
esc_html__( '%1$s requires PHP %2$s to work and does not support your current PHP version %3$s. Please contact your host and request a PHP upgrade to the latest one.', 'wp-mail-smtp' ),
|
||||
esc_html( $this->get_title() ),
|
||||
esc_html( $this->php ),
|
||||
esc_html( phpversion() )
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php esc_html_e( 'Meanwhile you can switch to some other mailers.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a helpful message to those users, that are using an outdated version of PHP,
|
||||
* which is not supported by the currently selected Provider.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected function display_ssl_warning() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - Provider name. */
|
||||
esc_html__( '%s requires a SSL certificate on a site to work and does not support your current installation. Please contact your host and request a SSL certificate or install a free one, like Let\'s Encrypt.', 'wp-mail-smtp' ),
|
||||
esc_html( $this->get_title() )
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php esc_html_e( 'Meanwhile you can switch to some other mailers.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a message of a constant that was set inside wp-config.php file.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $constant Constant name.
|
||||
*/
|
||||
protected function display_const_set_message( $constant ) {
|
||||
?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %1$s - constant name, %2$s - file name. */
|
||||
esc_html__( 'The value of this field was set using a constant %1$s most likely inside %2$s of your WordPress installation.', 'wp-mail-smtp' ),
|
||||
'<code>' . esc_attr( $constant ) . '</code>',
|
||||
'<code>wp-config.php</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
/**
|
||||
* Interface ProviderInterface, shared between all current and future providers.
|
||||
* Defines required methods across all providers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface OptionsInterface {
|
||||
|
||||
/**
|
||||
* Get the mailer provider slug.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_slug();
|
||||
|
||||
/**
|
||||
* Get the mailer provider title (or name).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title();
|
||||
|
||||
/**
|
||||
* Get the mailer provider description.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description();
|
||||
|
||||
/**
|
||||
* Get the mailer provider minimum PHP version.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_php_version();
|
||||
|
||||
/**
|
||||
* Get the mailer provider logo URL.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_logo_url();
|
||||
|
||||
/**
|
||||
* Output the mailer provider options.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function display_options();
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Outlook;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Outlook Options constructor.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/microsoft.svg',
|
||||
'slug' => 'outlook',
|
||||
'title' => esc_html__( 'Outlook', 'wp-mail-smtp' ),
|
||||
'disabled' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
?>
|
||||
|
||||
<p>
|
||||
<?php esc_html_e( 'We\'re sorry, the Microsoft Outlook mailer is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Pepipost;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer inherits everything from parent abstract class.
|
||||
* This file is required for a proper work of Loader and \ReflectionClass.
|
||||
*
|
||||
* @package WPMailSMTP\Providers\Pepipost
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->options->get_group( $this->mailer );
|
||||
|
||||
// Host and Port are the only really required options.
|
||||
if (
|
||||
! empty( $options['host'] ) &&
|
||||
! empty( $options['port'] )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Pepipost;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Pepipost constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/pepipost-smtp.png',
|
||||
'slug' => 'pepipost',
|
||||
'title' => esc_html__( 'Pepipost SMTP', 'wp-mail-smtp' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,440 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\PepipostAPI;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Mailer is basically a Sendgrid copy-paste, as Pepipost support SG migration.
|
||||
* In the future we may rewrite the class to use the native Pepipost API.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 202;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://sgapi.pepipost.com/v3/mail/send';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function __construct( $phpmailer ) {
|
||||
|
||||
// We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
|
||||
parent::__construct( $phpmailer );
|
||||
|
||||
$this->set_header( 'Authorization', 'Bearer ' . $this->options->get( $this->mailer, 'api_key' ) );
|
||||
$this->set_header( 'content-type', 'application/json' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way email body is returned.
|
||||
* By default we are sending an array of data.
|
||||
* Pepipost requires a JSON, so we encode the body.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
$body = parent::get_body();
|
||||
|
||||
return wp_json_encode( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the FROM header of the email.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @param string $email From mail.
|
||||
* @param string $name From name.
|
||||
*/
|
||||
public function set_from( $email, $name = '' ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$from['email'] = $email;
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$from['name'] = $name;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'from' => $from,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the names/emails of people who will receive the email.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @param array $recipients List of recipients: cc/bcc/to.
|
||||
*/
|
||||
public function set_recipients( $recipients ) {
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow for now only these recipient types.
|
||||
$default = array( 'to', 'cc', 'bcc' );
|
||||
$data = array();
|
||||
|
||||
foreach ( $recipients as $type => $emails ) {
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[ $type ] = array();
|
||||
|
||||
// Iterate over all emails for each type.
|
||||
// There might be multiple cc/to/bcc emails.
|
||||
foreach ( $emails as $email ) {
|
||||
$holder = array();
|
||||
$addr = isset( $email[0] ) ? $email[0] : false;
|
||||
$name = isset( $email[1] ) ? $email[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$holder['email'] = $addr;
|
||||
if ( ! empty( $name ) ) {
|
||||
$holder['name'] = $name;
|
||||
}
|
||||
|
||||
array_push( $data[ $type ], $holder );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'personalizations' => array( $data ),
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! empty( $data['bcc'] ) ) {
|
||||
// Only the 1st BCC email address, ignore the rest - is not supported by Pepipost.
|
||||
$bcc['mail_settings']['bcc']['email'] = $data['bcc'][0]['email'];
|
||||
$this->set_body_param(
|
||||
$bcc
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the email content.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @param array|string $content Email content.
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
|
||||
$default = array( 'text', 'html' );
|
||||
$data = array();
|
||||
|
||||
foreach ( $content as $type => $body ) {
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $body )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content_type = 'text/plain';
|
||||
$content_value = $body;
|
||||
|
||||
if ( $type === 'html' ) {
|
||||
$content_type = 'text/html';
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'type' => $content_type,
|
||||
'value' => $content_value,
|
||||
);
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'content' => $data,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$data['type'] = 'text/html';
|
||||
$data['value'] = $content;
|
||||
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$data['type'] = 'text/plain';
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'content' => array( $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @param array $headers
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = isset( $this->body['headers'] ) ? (array) $this->body['headers'] : array();
|
||||
|
||||
$headers[ $name ] = WP::sanitize_value( $value );
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'headers' => $headers,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pepipost accepts an array of files content in body, so we will include all files and send.
|
||||
* Doesn't handle exceeding the limits etc, as this is done and reported by SendGrid API.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @param array $attachments
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = false;
|
||||
|
||||
/*
|
||||
* We are not using WP_Filesystem API as we can't reliably work with it.
|
||||
* It is not always available, same as credentials for FTP.
|
||||
*/
|
||||
try {
|
||||
if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
|
||||
$file = file_get_contents( $attachment[0] ); // phpcs:ignore
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {
|
||||
$file = false;
|
||||
}
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'content' => base64_encode( $file ),
|
||||
'type' => $attachment[4],
|
||||
'filename' => $attachment[2],
|
||||
'disposition' => $attachment[6],
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'attachments' => $data,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the reply-to property of the email.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @param array $reply_to Name/email for reply-to feature.
|
||||
*/
|
||||
public function set_reply_to( $reply_to ) {
|
||||
|
||||
if ( empty( $reply_to ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $reply_to as $key => $emails ) {
|
||||
if (
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$addr = isset( $emails[0] ) ? $emails[0] : false;
|
||||
$name = isset( $emails[1] ) ? $emails[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data['email'] = $addr;
|
||||
if ( ! empty( $name ) ) {
|
||||
$data['name'] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'reply_to' => $data,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pepipost doesn't support sender or return_path params.
|
||||
* So we do nothing.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @param string $from_email
|
||||
*/
|
||||
public function set_return_path( $from_email ) {}
|
||||
|
||||
/**
|
||||
* Get a Pepipost-specific response with a helpful error.
|
||||
*
|
||||
* @see https://developers.pepipost.com/migration-api/new-subpage/errorcodes
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_response_error() {
|
||||
|
||||
$body = (array) wp_remote_retrieve_body( $this->response );
|
||||
|
||||
$error_text = array();
|
||||
|
||||
if ( ! empty( $body['errors'] ) ) {
|
||||
foreach ( $body['errors'] as $error ) {
|
||||
if ( property_exists( $error, 'message' ) ) {
|
||||
// Prepare additional information from SendGrid API.
|
||||
$extra = '';
|
||||
if ( property_exists( $error, 'field' ) && ! empty( $error->field ) ) {
|
||||
$extra .= $error->field . '; ';
|
||||
}
|
||||
if ( property_exists( $error, 'help' ) && ! empty( $error->help ) ) {
|
||||
$extra .= $error->help;
|
||||
}
|
||||
|
||||
// Assign both the main message and perhaps extra information, if exists.
|
||||
$error_text[] = $error->message . ( ! empty( $extra ) ? ' - ' . $extra : '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return implode( '<br>', array_map( 'esc_textarea', $error_text ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mailer debug information, that is helpful during support.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$sendgrid_text[] = '<strong>Api Key:</strong> ' . ( $this->is_mailer_complete() ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $sendgrid_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->options->get_group( $this->mailer );
|
||||
|
||||
// API key is the only required option.
|
||||
if ( ! empty( $options['api_key'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\PepipostAPI;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
use WPMailSMTP\Options as PluginOptions;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
const SLUG = 'pepipostapi';
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$description = sprintf(
|
||||
wp_kses( /* translators: %1$s - URL to pepipost.com site. */
|
||||
__( '<strong><a href="%1$s" target="_blank" rel="noopener noreferrer">Pepipost</a> is a recommended transactional email service.</strong> Every month Pepipost delivers over 8 billion emails from 20,000+ customers. Their mission is to reliably send emails in the most efficient way and at the most disruptive pricing ever. Pepipost provides users 30,000 free emails the first 30 days.', 'wp-mail-smtp' ) .
|
||||
'<br><br>' .
|
||||
/* translators: %1$s - URL to wpmailsmtp.com doc. */
|
||||
__( 'Read our <a href="%2$s" target="_blank" rel="noopener noreferrer">Pepipost documentation</a> to learn how to configure Pepipost and improve your email deliverability.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => true,
|
||||
'strong' => true,
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'rel' => true,
|
||||
'target' => true,
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://wpmailsmtp.com/go/pepipost/',
|
||||
'https://wpmailsmtp.com/docs/how-to-set-up-the-pepipost-mailer-in-wp-mail-smtp'
|
||||
);
|
||||
|
||||
$api_key = PluginOptions::init()->get( self::SLUG, 'api_key' );
|
||||
|
||||
if ( empty( $api_key ) ) {
|
||||
$description .= '</p><p class="buttonned"><a href="https://wpmailsmtp.com/go/pepipost/" target="_blank" rel="noopener noreferrer" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-blueish">' .
|
||||
esc_html__( 'Get Pepipost Now (Free)', 'wp-mail-smtp' ) .
|
||||
'</a></p>';
|
||||
}
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/pepipost.png',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'Pepipost', 'wp-mail-smtp' ),
|
||||
'description' => $description,
|
||||
'recommended' => true,
|
||||
'php' => '5.3',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the mailer provider options.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
// Do not display options if PHP version is not correct.
|
||||
if ( ! $this->is_php_correct() ) {
|
||||
$this->display_php_warning();
|
||||
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- API Key -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_id"
|
||||
class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_PEPIPOST_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %s - pepipost.com link to get an API Key. */
|
||||
esc_html__( 'Follow this link to get an API Key: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.pepipost.com/app/settings/integration" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get the API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTP;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer inherits everything from parent abstract class.
|
||||
* This file is required for a proper work of Loader and \ReflectionClass.
|
||||
*
|
||||
* @package WPMailSMTP\Providers\SMTP
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->options->get_group( $this->mailer );
|
||||
|
||||
// Host and Port are the only really required options.
|
||||
if (
|
||||
! empty( $options['host'] ) &&
|
||||
! empty( $options['port'] )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTP;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class SMTP.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* SMTP constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/smtp.svg',
|
||||
'slug' => 'smtp',
|
||||
'title' => esc_html__( 'Other SMTP', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %s - URL to a related article on WPForms.com. */
|
||||
__( 'Use the SMTP details provided by your hosting provider or email service.<br><br>To see recommended settings for the popular services as well as troubleshooting tips, check out our <a href="%s" target="_blank" rel="noopener noreferrer">SMTP documentation</a>.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://wpmailsmtp.com/docs/how-to-set-up-the-other-smtp-mailer-in-wp-mail-smtp/'
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,409 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendgrid;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 202;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.sendgrid.com/v3/mail/send';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function __construct( $phpmailer ) {
|
||||
|
||||
// We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
|
||||
parent::__construct( $phpmailer );
|
||||
|
||||
$this->set_header( 'Authorization', 'Bearer ' . $this->options->get( $this->mailer, 'api_key' ) );
|
||||
$this->set_header( 'content-type', 'application/json' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way email body is returned.
|
||||
* By default we are sending an array of data.
|
||||
* SendGrid requires a JSON, so we encode the body.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
$body = parent::get_body();
|
||||
|
||||
return wp_json_encode( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_from( $email, $name = '' ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$from['email'] = $email;
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$from['name'] = $name;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'from' => $from,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_recipients( $recipients ) {
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow for now only these recipient types.
|
||||
$default = array( 'to', 'cc', 'bcc' );
|
||||
$data = array();
|
||||
|
||||
foreach ( $recipients as $type => $emails ) {
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[ $type ] = array();
|
||||
|
||||
// Iterate over all emails for each type.
|
||||
// There might be multiple cc/to/bcc emails.
|
||||
foreach ( $emails as $email ) {
|
||||
$holder = array();
|
||||
$addr = isset( $email[0] ) ? $email[0] : false;
|
||||
$name = isset( $email[1] ) ? $email[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$holder['email'] = $addr;
|
||||
if ( ! empty( $name ) ) {
|
||||
$holder['name'] = $name;
|
||||
}
|
||||
|
||||
array_push( $data[ $type ], $holder );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'personalizations' => array( $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
|
||||
$default = array( 'text', 'html' );
|
||||
$data = array();
|
||||
|
||||
foreach ( $content as $type => $body ) {
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $body )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content_type = 'text/plain';
|
||||
$content_value = $body;
|
||||
|
||||
if ( $type === 'html' ) {
|
||||
$content_type = 'text/html';
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'type' => $content_type,
|
||||
'value' => $content_value,
|
||||
);
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'content' => $data,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$data['type'] = 'text/html';
|
||||
$data['value'] = $content;
|
||||
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$data['type'] = 'text/plain';
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'content' => array( $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param array $headers
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = isset( $this->body['headers'] ) ? (array) $this->body['headers'] : array();
|
||||
|
||||
$headers[ $name ] = WP::sanitize_value( $value );
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'headers' => $headers,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SendGrid accepts an array of files content in body, so we will include all files and send.
|
||||
* Doesn't handle exceeding the limits etc, as this is done and reported by SendGrid API.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $attachments
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = false;
|
||||
|
||||
/*
|
||||
* We are not using WP_Filesystem API as we can't reliably work with it.
|
||||
* It is not always available, same as credentials for FTP.
|
||||
*/
|
||||
try {
|
||||
if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
|
||||
$file = file_get_contents( $attachment[0] ); // phpcs:ignore
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {
|
||||
$file = false;
|
||||
}
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filetype = str_replace( ';', '', trim( $attachment[4] ) );
|
||||
|
||||
$data[] = array(
|
||||
'content' => base64_encode( $file ), // string, 1 character.
|
||||
'type' => $filetype, // string, no ;, no CRLF.
|
||||
'filename' => empty( $attachment[2] ) ? 'file-' . wp_hash( microtime() ) . '.' . $filetype : trim( $attachment[2] ), // required string, no CRLF.
|
||||
'disposition' => in_array( $attachment[6], array( 'inline', 'attachment' ), true ) ? $attachment[6] : 'attachment', // either inline or attachment.
|
||||
'content_id' => empty( $attachment[7] ) ? '' : trim( (string) $attachment[7] ), // string, no CRLF.
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'attachments' => $data,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function set_reply_to( $reply_to ) {
|
||||
|
||||
if ( empty( $reply_to ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $reply_to as $key => $emails ) {
|
||||
if (
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$addr = isset( $emails[0] ) ? $emails[0] : false;
|
||||
$name = isset( $emails[1] ) ? $emails[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data['email'] = $addr;
|
||||
if ( ! empty( $name ) ) {
|
||||
$data['name'] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'reply_to' => $data,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SendGrid doesn't support sender or return_path params.
|
||||
* So we do nothing.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $from_email
|
||||
*/
|
||||
public function set_return_path( $from_email ) {}
|
||||
|
||||
/**
|
||||
* Get a SendGrid-specific response with a helpful error.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_response_error() {
|
||||
|
||||
$body = (array) wp_remote_retrieve_body( $this->response );
|
||||
|
||||
$error_text = array();
|
||||
|
||||
if ( ! empty( $body['errors'] ) ) {
|
||||
foreach ( $body['errors'] as $error ) {
|
||||
if ( property_exists( $error, 'message' ) ) {
|
||||
// Prepare additional information from SendGrid API.
|
||||
$extra = '';
|
||||
if ( property_exists( $error, 'field' ) && ! empty( $error->field ) ) {
|
||||
$extra .= $error->field . '; ';
|
||||
}
|
||||
if ( property_exists( $error, 'help' ) && ! empty( $error->help ) ) {
|
||||
$extra .= $error->help;
|
||||
}
|
||||
|
||||
// Assign both the main message and perhaps extra information, if exists.
|
||||
$error_text[] = $error->message . ( ! empty( $extra ) ? ' - ' . $extra : '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return implode( '<br>', array_map( 'esc_textarea', $error_text ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mailer debug information, that is helpful during support.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$sendgrid_text[] = '<strong>Api Key:</strong> ' . ( $this->is_mailer_complete() ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $sendgrid_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->options->get_group( $this->mailer );
|
||||
|
||||
// API key is the only required option.
|
||||
if ( ! empty( $options['api_key'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendgrid;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/sendgrid.svg',
|
||||
'slug' => 'sendgrid',
|
||||
'title' => esc_html__( 'SendGrid', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
|
||||
__( '%1$sSendGrid%2$s is one of the leading transactional email services, sending over 35 billion emails every month. They provide users 100 free emails per day.<br><br>Read our %3$sSendGrid documentation%4$s to learn how to set up SendGrid and improve your email deliverability.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'<a href="https://sendgrid.com" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>',
|
||||
'<a href="https://wpmailsmtp.com/docs/how-to-set-up-the-sendgrid-mailer-in-wp-mail-smtp/" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<!-- API Key -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_SENDGRID_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - API key link. */
|
||||
esc_html__( 'Follow this link to get an API Key from SendGrid: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.sendgrid.com/settings/api_keys" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Create API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
<br/>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - SendGrid access level. */
|
||||
esc_html__( 'To send emails you will need only a %s access level for this API key.', 'wp-mail-smtp' ),
|
||||
'<code>Mail Send</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendinblue;
|
||||
|
||||
/**
|
||||
* Class Api is a wrapper for Sendinblue library with handy methods.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class Api {
|
||||
|
||||
/**
|
||||
* Contains mailer options, constants + DB values.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* API constructor that inits defaults and retrieves options.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->options = \WPMailSMTP\Options::init()->get_group( Options::SLUG );
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure API key authorization: api-key.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @return \SendinBlue\Client\Configuration
|
||||
*/
|
||||
protected function get_api_config() {
|
||||
|
||||
return \SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey( 'api-key', isset( $this->options['api_key'] ) ? $this->options['api_key'] : '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mailer client instance for Account API.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function get_account_client() {
|
||||
|
||||
// Include the library.
|
||||
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
|
||||
return new \SendinBlue\Client\Api\AccountApi( null, $this->get_api_config() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mailer client instance for Sender API.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function get_sender_client() {
|
||||
|
||||
// Include the library.
|
||||
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
|
||||
return new \SendinBlue\Client\Api\SendersApi( null, $this->get_api_config() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mailer client instance for SMTP API.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function get_smtp_client() {
|
||||
|
||||
// Include the library.
|
||||
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
|
||||
return new \SendinBlue\Client\Api\SMTPApi( null, $this->get_api_config() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer is ready to be used in API calls.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_ready() {
|
||||
|
||||
return ! empty( $this->options['api_key'] );
|
||||
}
|
||||
}
|
@ -0,0 +1,393 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendinblue;
|
||||
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 201;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
* Not actually used, because we use a lib to make requests.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.sendinblue.com/v3';
|
||||
|
||||
/**
|
||||
* The list of allowed attachment files extensions.
|
||||
*
|
||||
* @see https://developers.sendinblue.com/reference#sendTransacEmail_attachment__title
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
// @formatter:off
|
||||
protected $allowed_attach_ext = array( 'xlsx', 'xls', 'ods', 'docx', 'docm', 'doc', 'csv', 'pdf', 'txt', 'gif', 'jpg', 'jpeg', 'png', 'tif', 'tiff', 'rtf', 'bmp', 'cgm', 'css', 'shtml', 'html', 'htm', 'zip', 'xml', 'ppt', 'pptx', 'tar', 'ez', 'ics', 'mobi', 'msg', 'pub', 'eps', 'odt', 'mp3', 'm4a', 'm4v', 'wma', 'ogg', 'flac', 'wav', 'aif', 'aifc', 'aiff', 'mp4', 'mov', 'avi', 'mkv', 'mpeg', 'mpg', 'wmv' );
|
||||
// @formatter:on
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function __construct( $phpmailer ) {
|
||||
|
||||
parent::__construct( $phpmailer );
|
||||
|
||||
if ( ! $this->is_php_compatible() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function set_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
|
||||
$this->body['headers'][ $name ] = WP::sanitize_value( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the From information for an email.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param string $email
|
||||
* @param string $name
|
||||
*/
|
||||
public function set_from( $email, $name ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->body['sender'] = array(
|
||||
'email' => $email,
|
||||
'name' => ! empty( $name ) ? WP::sanitize_value( $name ) : '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email recipients: to, cc, bcc.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param array $recipients
|
||||
*/
|
||||
public function set_recipients( $recipients ) {
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow for now only these recipient types.
|
||||
$default = array( 'to', 'cc', 'bcc' );
|
||||
$data = array();
|
||||
|
||||
foreach ( $recipients as $type => $emails ) {
|
||||
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[ $type ] = array();
|
||||
|
||||
// Iterate over all emails for each type.
|
||||
// There might be multiple cc/to/bcc emails.
|
||||
foreach ( $emails as $email ) {
|
||||
$holder = array();
|
||||
$addr = isset( $email[0] ) ? $email[0] : false;
|
||||
$name = isset( $email[1] ) ? $email[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$holder['email'] = $addr;
|
||||
if ( ! empty( $name ) ) {
|
||||
$holder['name'] = $name;
|
||||
}
|
||||
|
||||
array_push( $data[ $type ], $holder );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $data as $type => $type_recipients ) {
|
||||
$this->body[ $type ] = $type_recipients;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function set_subject( $subject ) {
|
||||
|
||||
$this->body['subject'] = $subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email content.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param string|array $content
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
|
||||
if ( ! empty( $content['text'] ) ) {
|
||||
$this->body['textContent'] = $content['text'];
|
||||
}
|
||||
|
||||
if ( ! empty( $content['html'] ) ) {
|
||||
$this->body['htmlContent'] = $content['html'];
|
||||
}
|
||||
} else {
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$this->body['textContent'] = $content;
|
||||
} else {
|
||||
$this->body['htmlContent'] = $content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't support this.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param string $email
|
||||
*/
|
||||
public function set_return_path( $email ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Reply To headers if not set already.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param array $emails
|
||||
*/
|
||||
public function set_reply_to( $emails ) {
|
||||
|
||||
if ( empty( $emails ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $emails as $user ) {
|
||||
$holder = array();
|
||||
$addr = isset( $user[0] ) ? $user[0] : false;
|
||||
$name = isset( $user[1] ) ? $user[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$holder['email'] = $addr;
|
||||
if ( ! empty( $name ) ) {
|
||||
$holder['name'] = $name;
|
||||
}
|
||||
|
||||
$data[] = $holder;
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->body['replyTo'] = $data[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attachments for an email.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param array $attachments
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = false;
|
||||
|
||||
/*
|
||||
* We are not using WP_Filesystem API as we can't reliably work with it.
|
||||
* It is not always available, same as credentials for FTP.
|
||||
*/
|
||||
try {
|
||||
if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
|
||||
$ext = pathinfo( $attachment[0], PATHINFO_EXTENSION );
|
||||
|
||||
if ( in_array( $ext, $this->allowed_attach_ext, true ) ) {
|
||||
$file = file_get_contents( $attachment[0] ); // phpcs:ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {
|
||||
$file = false;
|
||||
}
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->body['attachment'][] = array(
|
||||
'name' => $attachment[2],
|
||||
'content' => base64_encode( $file ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @return \SendinBlue\Client\Model\SendSmtpEmail
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
return new \SendinBlue\Client\Model\SendSmtpEmail( $this->body );
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a library to send emails.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function send() {
|
||||
|
||||
try {
|
||||
$api = new Api();
|
||||
|
||||
$response = $api->get_smtp_client()->sendTransacEmail( $this->get_body() );
|
||||
|
||||
$this->process_response( $response );
|
||||
}
|
||||
catch ( \SendinBlue\Client\ApiException $e ) {
|
||||
$error = json_decode( $e->getResponseBody() );
|
||||
if ( json_last_error() === JSON_ERROR_NONE ) {
|
||||
Debug::set(
|
||||
'Mailer: Sendinblue' . "\r\n" .
|
||||
'[' . sanitize_key( $error->code ) . ']: ' . esc_html( $error->message )
|
||||
);
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {
|
||||
Debug::set(
|
||||
'Mailer: Sendinblue' . "\r\n" .
|
||||
$e->getMessage()
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save response from the API to use it later.
|
||||
* All the actually response processing is done in send() method,
|
||||
* because SendinBlue throws exception if any error occurs.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param \SendinBlue\Client\Model\CreateSmtpEmail $response
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the email was sent.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_email_sent() {
|
||||
|
||||
$is_sent = false;
|
||||
|
||||
if ( $this->response instanceof \SendinBlue\Client\Model\CreateSmtpEmail ) {
|
||||
$is_sent = $this->response->valid();
|
||||
}
|
||||
|
||||
// Clear debug messages if email is successfully sent.
|
||||
if ( $is_sent ) {
|
||||
Debug::clear();
|
||||
}
|
||||
|
||||
return $is_sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$mailjet_text[] = '<strong>API Key:</strong> ' . ( $this->is_mailer_complete() ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $mailjet_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->options->get_group( $this->mailer );
|
||||
|
||||
// API key is the only required option.
|
||||
if ( ! empty( $options['api_key'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendinblue;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
use WPMailSMTP\Options as PluginOptions;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
const SLUG = 'sendinblue';
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$description = sprintf(
|
||||
wp_kses( /* translators: %1$s - URL to sendinblue.com site. */
|
||||
__( '<strong><a href="%1$s" target="_blank" rel="noopener noreferrer">Sendinblue</a> is a recommended transactional email service.</strong> Founded in 2012, they serve 80,000+ growing companies around the world and send over 30 million emails each day. They understand that transactional emails are the heart of your customer relationships. Their email deliverability experts are constantly at work optimizing the reliability and speed of their SMTP infrastructure. Sendinblue provides users 300 free emails per day.', 'wp-mail-smtp' ) .
|
||||
'<br><br>' .
|
||||
/* translators: %2$s - URL to wpmailsmtp.com doc. */
|
||||
__( 'Read our <a href="%2$s" target="_blank" rel="noopener noreferrer">Sendinblue documentation</a> to learn how to configure Sendinblue and improve your email deliverability.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => true,
|
||||
'strong' => true,
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'rel' => true,
|
||||
'target' => true,
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://wpmailsmtp.com/go/sendinblue/',
|
||||
'https://wpmailsmtp.com/docs/how-to-set-up-the-sendinblue-mailer-in-wp-mail-smtp'
|
||||
);
|
||||
|
||||
$api_key = PluginOptions::init()->get( self::SLUG, 'api_key' );
|
||||
|
||||
if ( empty( $api_key ) ) {
|
||||
$description .= '</p><p class="buttonned"><a href="https://wpmailsmtp.com/go/sendinblue/" target="_blank" rel="noopener noreferrer" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-blueish">' .
|
||||
esc_html__( 'Get Sendinblue Now (Free)', 'wp-mail-smtp' ) .
|
||||
'</a></p>';
|
||||
}
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/sendinblue.svg',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'Sendinblue', 'wp-mail-smtp' ),
|
||||
'description' => $description,
|
||||
'recommended' => true,
|
||||
'php' => '5.6',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the mailer provider options.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
// Do not display options if PHP version is not correct.
|
||||
if ( ! $this->is_php_correct() ) {
|
||||
$this->display_php_warning();
|
||||
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- API Key -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_id"
|
||||
class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_SENDINBLUE_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %s - sendinblue.com link to get an API Key. */
|
||||
esc_html__( 'Follow this link to get an API Key: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://account.sendinblue.com/advanced/api" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get v3 API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user