{"id":17406182,"date":"2024-02-07T14:28:04","date_gmt":"2024-02-07T14:28:04","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/code-error-41\/"},"modified":"2024-02-07T14:28:04","modified_gmt":"2024-02-07T14:28:04","slug":"code-error-41","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/code-error-41\/","title":{"rendered":"Code Error"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I have raised this before with you by email but nothing has been done. I believe there is an issue with the code of this plugin which creates php errors when emails do not send due to a server problem.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The code below comes at the end of transmail.php. First it tries to get the variable $details from $responseData. However if there is no server connection then $responseData is not present so it throws up an error. Secondly it seems you are using $message for two different items. The first is the error message and the second is the email message as part of $mail_data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please do not ask me to email your team with this as I have done it before and nothing was done. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if($http_code == '200' || $http_code == '201') {\n  return true;\n}\n\n$details = $responseData-&gt;error-&gt;details;\n$message = $details&#091;0]-&gt;message;\n\n$mail_data = array(\n  'to' =&gt; $to,\n  'subject' =&gt; $subject,\n  'message' =&gt; $message,\n  'headers' =&gt; $headers1,\n  'attachments' =&gt; $attachments\n);\n\ndo_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $message, $mail_data ) );\nreturn false;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">My current workaround to avoid php errors and be able to correctly log when emails are not sent in my mail logger is this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if($http_code == '200' || $http_code == '201') {\n  return true;\n}\n\/*\n$details = $responseData-&gt;error-&gt;details;\n$message = $details&#091;0]-&gt;message;\n*\/\n$mail_data = array(\n  'to' =&gt; $to,\n  'subject' =&gt; $subject,\n  'message' =&gt; $message,\n  'headers' =&gt; $headers1,\n  'attachments' =&gt; $attachments\n);\n\ndo_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', 'No Response from Server', $mail_data ) );\nreturn false;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If I am wrong about this then please accept my apologies.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Many thanks<\/p>\n","protected":false},"template":"","class_list":["post-17406182","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17406182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/17406182\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=17406182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}