Skip to content

Instantly share code, notes, and snippets.

@niladam
Created March 14, 2017 12:11
Show Gist options
  • Save niladam/4daed49ed69acf152a53b8bfd8dd4a52 to your computer and use it in GitHub Desktop.
Save niladam/4daed49ed69acf152a53b8bfd8dd4a52 to your computer and use it in GitHub Desktop.
Disable WordPress email based on subject or any other variable
<?php
add_filter('phpmailer_init', 'stopCartNotifications');
function stopCartNotifications( $phpmailer ) {
// Let's extract object variables so we can use them.
$variabile = get_object_vars($phpmailer);
// I' blocking based on subject so, i'm selecting Subject from the object below in phpmailer_object_data.php
$subiect_email = $variabile['Subject'];
// I'm searching for Contact from the blog... (Calculated Form Fields)
if ( !empty($subiect_email) && $subiect_email == 'Contact from the blog...')
// Well, the subject matches, let's clear the email.
$phpmailer->ClearAllRecipients();
}
<?php
// This is what $phpmailer from above contains. You can basically
PHPMailer Object
(
[Version] => 5.2.22
[Priority] =>
[CharSet] => utf-8
[ContentType] => text/plain
[Encoding] => 8bit
[ErrorInfo] => Invalid address: (addAnAddress Reply-To):
[From] => [email protected]
[FromName] => [email protected]
[Sender] =>
[ReturnPath] =>
[Subject] => Contact from the blog...
[Body] =>
[AltBody] =>
[Ical] =>
[MIMEBody:protected] =>
[MIMEHeader:protected] =>
[mailHeader:protected] =>
[WordWrap] => 0
[Mailer] => mail
[Sendmail] => /usr/sbin/sendmail
[UseSendmailOptions] => 1
[PluginDir] =>
[ConfirmReadingTo] =>
[Hostname] =>
[MessageID] =>
[MessageDate] =>
[Host] => localhost
[Port] => 25
[Helo] =>
[SMTPSecure] =>
[SMTPAutoTLS] => 1
[SMTPAuth] =>
[SMTPOptions] => Array
(
)
[Username] =>
[Password] =>
[AuthType] =>
[Realm] =>
[Workstation] =>
[Timeout] => 300
[SMTPDebug] => 0
[Debugoutput] => echo
[SMTPKeepAlive] =>
[SingleTo] =>
[SingleToArray] => Array
(
)
[do_verp] =>
[AllowEmpty] =>
[LE] =>
[DKIM_selector] =>
[DKIM_identity] =>
[DKIM_passphrase] =>
[DKIM_domain] =>
[DKIM_private] =>
[DKIM_private_string] =>
[action_function] =>
[XMailer] =>
[smtp:protected] =>
[to:protected] => Array
(
[0] => Array
(
[0] => [email protected]
[1] =>
)
)
[cc:protected] => Array
(
)
[bcc:protected] => Array
(
)
[ReplyTo:protected] => Array
(
)
[all_recipients:protected] => Array
(
[[email protected]] => 1
)
[RecipientsQueue:protected] => Array
(
)
[ReplyToQueue:protected] => Array
(
)
[attachment:protected] => Array
(
)
[CustomHeader:protected] => Array
(
[0] => Array
(
[0] => X-Mailer
[1] => PHP/7.0.16
)
)
[lastMessageID:protected] =>
[message_type:protected] =>
[boundary:protected] => Array
(
)
[language:protected] => Array
(
[authenticate] => SMTP Error: Could not authenticate.
[connect_host] => SMTP Error: Could not connect to SMTP host.
[data_not_accepted] => SMTP Error: data not accepted.
[empty_message] => Message body empty
[encoding] => Unknown encoding:
[execute] => Could not execute:
[file_access] => Could not access file:
[file_open] => File Error: Could not open file:
[from_failed] => The following From address failed:
[instantiate] => Could not instantiate mail function.
[invalid_address] => Invalid address:
[mailer_not_supported] => mailer is not supported.
[provide_address] => You must provide at least one recipient email address.
[recipients_failed] => SMTP Error: The following recipients failed:
[signing] => Signing Error:
[smtp_connect_failed] => SMTP connect() failed.
[smtp_error] => SMTP server error:
[variable_set] => Cannot set or reset variable:
[extension_missing] => Extension missing:
)
[error_count:protected] => 1
[sign_cert_file:protected] =>
[sign_key_file:protected] =>
[sign_extracerts_file:protected] =>
[sign_key_pass:protected] =>
[exceptions:protected] => 1
[uniqueid:protected] =>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment