summaryrefslogtreecommitdiff
path: root/Postman/PostmanWpMail.php
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2019-05-15 12:14:32 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2019-05-15 12:14:32 +0000
commit38153c0f3e739f3d89a1a7734fd7d199bf457fab (patch)
tree28e19f4e091d5182a2c63bc98377e5381b0043ac /Postman/PostmanWpMail.php
parent942aa536210fe204a2d097eb8878c1d690e0547b (diff)
downloadPost-SMTP-38153c0f3e739f3d89a1a7734fd7d199bf457fab.zip
= 2.0 - 2019-05-15
* New: Mailer Type - Added an option to send without overwrite the 'wp_mail' function, better compability to WordPress delivery. hopefully will be the default in the future. * Updated: Sendgrid API was upgraded and rewritten to the new version. * Fixed: Message-Id header was missing on SMTP * Fixed: Email logger optimization - better query for large amount of records. * Fixed: The localization was fixed to match translate.wordpress.org translation system ( Thanks to Niels de Blaauw from Level-Level ). * Fixed: Code and optimization ( Thanks to Niels de Blaauw from Level-Level ).
Diffstat (limited to 'Postman/PostmanWpMail.php')
-rw-r--r--Postman/PostmanWpMail.php75
1 files changed, 54 insertions, 21 deletions
diff --git a/Postman/PostmanWpMail.php b/Postman/PostmanWpMail.php
index 173b35e..66b3279 100644
--- a/Postman/PostmanWpMail.php
+++ b/Postman/PostmanWpMail.php
@@ -1,4 +1,5 @@
<?php
+
if ( ! class_exists( 'PostmanWpMail' ) ) {
/**
@@ -29,11 +30,11 @@ if ( ! class_exists( 'PostmanWpMail' ) ) {
* Exceptions are held for later inspection.
* An instance of PostmanState updates the success/fail tally.
*
- * @param unknown $to
- * @param unknown $subject
- * @param unknown $body
- * @param unknown $headers
- * @param unknown $attachments
+ * @param mixed $to
+ * @param mixed $subject
+ * @param mixed $body
+ * @param mixed $headers
+ * @param mixed $attachments
* @return boolean
*/
public function send( $to, $subject, $message, $headers = '', $attachments = array() ) {
@@ -55,14 +56,41 @@ if ( ! class_exists( 'PostmanWpMail' ) ) {
return $this->sendMessage( $postmanMessage, $log );
}
+ /**
+ * @param PostmanMessage $message
+ * @return PostmanMessage
+ */
+ private function apply_default_headers( $message ) {
+ $headers[] = 'Message-ID: ' . $this->createMessageId();
+ $message->addHeaders($headers);
+ }
+
+ /**
+ * Creates the Message-ID
+ *
+ * @return string
+ */
+ public function createMessageId() {
+
+ $id = md5(uniqid(time()));
+
+ if (isset($_SERVER["SERVER_NAME"])) {
+ $hostName = $_SERVER["SERVER_NAME"];
+ } else {
+ $hostName = php_uname('n');
+ }
+
+ return $id . '@' . $hostName;
+ }
+
/**
* Builds a PostmanMessage based on the WordPress wp_mail parameters
*
- * @param unknown $to
- * @param unknown $subject
- * @param unknown $message
- * @param unknown $headers
- * @param unknown $attachments
+ * @param mixed $to
+ * @param mixed $subject
+ * @param mixed $message
+ * @param mixed $headers
+ * @param mixed $attachments
*/
private function processWpMailCall( $to, $subject, $message, $headers, $attachments ) {
$this->logger->trace( 'wp_mail parameters before applying WordPress wp_mail filter:' );
@@ -147,6 +175,8 @@ if ( ! class_exists( 'PostmanWpMail' ) ) {
*/
public function sendMessage( PostmanMessage $message, PostmanEmailLog $log ) {
+ $this->apply_default_headers( $message );
+
// get the Options and AuthToken
$options = PostmanOptions::getInstance();
$authorizationToken = PostmanOAuthToken::getInstance();
@@ -254,6 +284,9 @@ if ( ! class_exists( 'PostmanWpMail' ) ) {
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
// return failure
+ if ( PostmanOptions::getInstance()->getSmtpMailer() == 'phpmailer' ) {
+ throw new phpmailerException($e->getMessage(), $e->getCode());
+ }
return false;
}
@@ -282,7 +315,7 @@ if ( ! class_exists( 'PostmanWpMail' ) ) {
* Clean up after sending the mail
*
* @param PostmanZendMailEngine $engine
- * @param unknown $startTime
+ * @param mixed $startTime
*/
private function postSend( PostmanMailEngine $engine, $startTime, PostmanOptions $options, PostmanModuleTransport $transport ) {
// save the transcript
@@ -338,11 +371,11 @@ if ( ! class_exists( 'PostmanWpMail' ) ) {
/**
* Aggregates all the content into a Message to be sent to the MailEngine
*
- * @param unknown $to
- * @param unknown $subject
- * @param unknown $body
- * @param unknown $headers
- * @param unknown $attachments
+ * @param mixed $to
+ * @param mixed $subject
+ * @param mixed $body
+ * @param mixed $headers
+ * @param mixed $attachments
*/
private function populateMessageFromWpMailParams( PostmanMessage $message, $to, $subject, $body, $headers, $attachments ) {
$message->addHeaders( $headers );
@@ -356,11 +389,11 @@ if ( ! class_exists( 'PostmanWpMail' ) ) {
/**
* Trace the parameters to aid in debugging
*
- * @param unknown $to
- * @param unknown $subject
- * @param unknown $body
- * @param unknown $headers
- * @param unknown $attachments
+ * @param mixed $to
+ * @param mixed $subject
+ * @param mixed $body
+ * @param mixed $headers
+ * @param mixed $attachments
*/
private function traceParameters( $to, $subject, $message, $headers, $attachments ) {
$this->logger->trace( 'to:' );