/home/vianto5/hidalgoresidences.mx/wp-content/plugins/wp-mail-smtp/src/TestEmail
Edit: /home/vianto5/hidalgoresidences.mx/wp-content/plugins/wp-mail-smtp/src/TestEmail/TestEmail.php (23019B)
connection = $connection;
return $this;
}
/**
* Set the caller context (drives the X-Mailer-Type header).
*
* @since 4.9.0
*
* @param string $context One of the CONTEXT_* constants.
*
* @return self
*/
public function with_context( $context ) {
$this->context = (string) $context;
return $this;
}
/**
* Toggle HTML vs plain text body.
*
* @since 4.9.0
*
* @param bool $is_html True for HTML, false for plain text.
*
* @return self
*/
public function as_html( $is_html ) {
$this->is_html = (bool) $is_html;
return $this;
}
/**
* Toggle DomainChecker invocation after a successful send.
*
* @since 4.9.0
*
* @param bool $run True to run the domain check, false to skip.
*
* @return self
*/
public function with_domain_check( $run ) {
$this->run_domain_check = (bool) $run;
return $this;
}
/**
* Whether the send succeeded (with or without domain-check issues).
*
* @since 4.9.0
*
* @return bool
*/
public function is_successful() {
return $this->result === self::SUCCESS || $this->result === self::FAILED_DOMAIN_CHECK;
}
/**
* Get the raw result constant.
*
* @since 4.9.0
*
* @return int|null
*/
public function get_result() {
return $this->result;
}
/**
* Get the DomainChecker instance populated after a successful send (when enabled).
*
* @since 4.9.0
*
* @return DomainChecker|null
*/
public function get_domain_checker() {
return $this->domain_checker;
}
/**
* Get the connection used for the send.
*
* @since 4.9.0
*
* @return ConnectionInterface|null
*/
public function get_connection() {
return $this->connection;
}
/**
* Send the test email.
*
* Lifted from TestTab::process_post() with the form-data plumbing replaced by
* fluent setters; the wp_mail() / ob_start / DomainChecker block stays identical.
*
* @since 4.9.0
*
* @param string $recipient Recipient email address.
*
* @return int|null Result constant (SUCCESS, FAILED, FAILED_DOMAIN_CHECK), or null when validation failed.
*/
public function send( $recipient ) { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks -- Paired add_filter/remove_filter scope the HTML content-type to this single test send only; moving them to hooks() would change behavior.
$recipient = filter_var( wp_unslash( $recipient ), FILTER_VALIDATE_EMAIL );
if ( empty( $recipient ) ) {
return null;
}
if ( ! $this->connection ) {
$this->connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection();
}
$phpmailer = wp_mail_smtp()->get_processor()->get_phpmailer();
/* translators: %s - email address a test email will be sent to. */
$subject = 'WP Mail SMTP: ' . sprintf( esc_html__( 'Test email to %s', 'wp-mail-smtp' ), $recipient );
$headers = [ 'X-Mailer-Type:' . $this->context ];
if ( $this->is_html ) {
add_filter( 'wp_mail_content_type', [ __CLASS__, 'set_test_html_content_type' ] );
/* translators: %s - email address a test email will be sent to. */
$subject = 'WP Mail SMTP: HTML ' . sprintf( esc_html__( 'Test email to %s', 'wp-mail-smtp' ), $recipient );
$headers[] = 'Content-Type: text/html';
}
// Send the test mail.
$result = wp_mail(
$recipient,
$subject,
$this->get_email_message( $this->is_html ),
$headers
);
if ( $this->is_html ) {
remove_filter( 'wp_mail_content_type', [ __CLASS__, 'set_test_html_content_type' ] );
}
/*
* Notify a user about the results.
*/
if ( $result ) {
if ( $this->run_domain_check ) {
$connection_options = $this->connection->get_options();
$mailer = $connection_options->get( 'mail', 'mailer' );
$email = $connection_options->get( 'mail', 'from_email' );
$domain = '';
// Add the optional sending domain parameter.
if ( in_array( $mailer, [ 'mailgun', 'sendinblue', 'sendgrid' ], true ) ) {
$domain = $connection_options->get( $mailer, 'domain' );
}
$this->domain_checker = new DomainChecker( $mailer, $email, $domain );
$this->result = $this->domain_checker->no_issues() ? self::SUCCESS : self::FAILED_DOMAIN_CHECK;
} else {
$this->result = self::SUCCESS;
}
} else {
$this->result = self::FAILED;
}
return $this->result;
}
/**
* Get the email message that should be sent.
*
* @since 1.4.0
*
* @param bool $is_html Whether to send an HTML email or plain text.
*
* @return string
*/
private function get_email_message( $is_html = true ) {
// Default plain text version of the email.
$message = self::get_email_message_text();
if ( $is_html ) {
$message = $this->get_email_message_html();
}
return $message;
}
/**
* Get the HTML prepared message for test email.
*
* @since 1.4.0
*
* @return string
*/
private function get_email_message_html() {
ob_start();
?>
WP Mail SMTP Test Email
Thank you for trying out WP Mail SMTP. We're on a mission to make sure that your emails actually get delivered.
is_pro() ) : ?>
If you find this free plugin useful, please consider giving WP Mail SMTP Pro a try!
Syed Balkhi Co-Founder, WP Mail SMTP
|
is_pro() ) : ?>
Unlock Powerful Features with WP Mail SMTP Pro
Email Logging with Email Resending
Open & Click Tracking
Email Reports with Weekly Summary
Backup Mailer
Failed Email Alerts via Email, Slack, and SMS
World-Class Support
WP Mail SMTP users get $50 off, automatically applied at checkout
|
|
|
is_pro() ) {
// WP Mail SMTP Pro paid installed.
$message =
'Congrats, test email was sent successfully!
Thank you for trying out WP Mail SMTP. We are on a mission to make sure your emails actually get delivered.
- Syed Balkhi
Co-Founder, WP Mail SMTP';
} else {
// Free WP Mail SMTP is installed.
$message =
'Congrats, test email was sent successfully!
Thank you for trying out WP Mail SMTP. We are on a mission to make sure your emails actually get delivered.
If you find this free plugin useful, please consider giving WP Mail SMTP Pro a try!
https://wpmailsmtp.com/lite-upgrade/
Unlock These Powerful Features with WP Mail SMTP Pro:
+ Log all emails and resend failed emails from your email log
+ Track opens and clicks to measure the engagement
+ Get email reports with a weekly summary of your email activity
+ Use a backup mailer if your mail service goes down
+ Get notified of failed emails via email, Slack, or SMS
+ Get help from our world-class support team
- Syed Balkhi
Co-Founder, WP Mail SMTP';
}
// phpcs:enable
return $message;
}
/**
* Set the HTML content type for a test email.
*
* @since 1.4.0
*
* @return string
*/
public static function set_test_html_content_type() {
return 'text/html';
}
}