Notification Custom Email – Not pulling from email-content.php

Home Forums Quform WordPress Notification Custom Email – Not pulling from email-content.php

This topic is: resolved
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #26319
    katw
    Participant

    I have created a custom function per your docs: https://support.themecatcher.net/quform-wordpress-v2/guides/email/custom-notification-email-content

    custom-function.php

    add_action('quform_pre_send_notification_1_4', function (PHPMailer $mailer, Quform_Notification $notification, Quform_Form $form) {
    	ob_start();
    	include __DIR__ . '/email-content.php';
    	$mailer->Body = ob_get_clean();
    }, 10, 3);

    email-content.php contains mixed HTML/PHP.

    <table width="100%" cellpadding="10" cellspacing="0" border="0" style="background: #ffffff; border-bottom: 1px solid #d4d4d4; box-shadow: 0 2px 7px 0 rgba(0, 0, 0, 0.07);">
    <tr bgcolor="#efefef"><td valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 15px; font-weight: bold; color: #282828; border: 1px solid #d4d4d4; border-bottom: 0;">
    <h2>Submitted form data</h2>
    </td></tr>
    <tr bgcolor="#fcfcfc"><td valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #282828; line-height: 130%; border: 1px solid #d4d4d4; border-bottom-color: #fff;">
    <p>Firstname: <?php echo $form->getValueHtml('quform_1_3'); ?> <?php echo $form->getValueHtml('quform_1_6'); ?></p>
    etc
    </td></tr>
    </table>

    Question 1:

    It was unclear if email-content.php should be a fully formed HTML document with <meta><head><body> etc

    I am hoping YES as I need to provide custom CSS and metadata.

    Question 2:

    I have tested the custom notification but don’t get an email containing email-content.php, instead I get the usual content you can add in the notification builder.

    How do I make the notification use the content of email-content.php?

    • This topic was modified 5 years, 9 months ago by katw. Reason: fixed markup
    #26356
    katw
    Participant

    Hi Ally,

    any chance you could get back to me on this?

    Thanks

    #26396
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #26763
    katw
    Participant

    Hi Ally,

    Need your help urgently.

    The quform_pre_send_notification hooks are not running neither the ALL nor the element specific one _#_##.

    I am thinking it has something to do with your assumption PHPMailer $mailer ???

    I am getting emails, but the hooks are not operating so the body contents are not populated as intended.

    My email routing is going through the ZOHO MAIL plugin. https://wordpress.org/plugins/zoho-mail/

    They appear to be hooking in as wp_mail.

    The sending function is below:

    if(!function_exists('wp_mail')) {
      function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { 
        
        $atts = apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) );
    
        if ( isset( $atts['to'] ) ) {
            $to = $atts['to'];
        }
        if ( !is_array( $to ) ) {
            $to = explode( ',', $to );
        }
        if ( isset( $atts['subject'] ) ) {
            $subject = $atts['subject'];
        }
        if ( isset( $atts['message'] ) ) {
            $message = $atts['message'];
        }
        if ( isset( $atts['headers'] ) ) {
            $headers = $atts['headers'];
        }
        if ( isset( $atts['attachments'] ) ) {
            $attachments = $atts['attachments'];
        }
    
        if ( ! is_array( $attachments ) ) {
            $attachments = implode( "\n", str_replace( "\r\n", "\n", $attachments ) );
        }
            
    
        // Headers
        $cc = $bcc = $reply_to = array();
        if ( empty( $headers ) ) {
            $headers = array();
          } else {
             if ( !is_array( $headers ) ) {
                // Explode the headers out, so this function can take both
                // string headers and an array of headers.
                $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
            } else {
                $tempheaders = $headers;
            }
            $headers = array();
    
            // If it's actually got contents
            if ( !empty( $tempheaders ) ) {
                // Iterate through the raw headers
                foreach ( (array) $tempheaders as $header ) {
                    if ( strpos($header, ':') === false ) {
                        if ( false !== stripos( $header, 'boundary=' ) ) {
                            $parts = preg_split('/boundary=/i', trim( $header ) );
                            $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
                        }
                        continue;
                    }
                    // Explode them out
                    list( $name, $content ) = explode( ':', trim( $header ), 2 );
    
                    // Cleanup crew
                    $name    = trim( $name    );
                    $content = trim( $content );
    
                    switch ( strtolower( $name ) ) {
                        case 'content-type':
                            if ( strpos( $content, ';' ) !== false ) {
                                list( $type, $charset_content ) = explode( ';', $content );
                                $content_type = trim( $type );
                                if ( false !== stripos( $charset_content, 'charset=' ) ) {
                                    $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) );
                                } elseif ( false !== stripos( $charset_content, 'boundary=' ) ) {
                                    $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) );
                                    $charset = '';
                                }
    
                            // Avoid setting an empty $content_type.
                              } elseif ( '' !== trim( $content ) ) {
                                      $content_type = trim( $content );
                                }
                               break;
                            case 'cc':
                                $cc = array_merge( (array) $cc, explode( ',', $content ) );
                                break;
                            case 'bcc':
                                $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
                                break;
                            case 'reply-to':
                                $reply_to = array_merge( (array) $reply_to, explode( ',', $content ) );
                                break;
                            default:
                                $headers[trim( $name )] = trim( $content );
                                break;
                            }
                         }
                      }
                    } 
                    $data = array();
                    $fromName = get_option('zmail_integ_from_name');
                    if (!empty($fromName)) {
                         $data['fromAddress'] = get_option('zmail_integ_from_name').'<'.get_option('zmail_integ_from_email_id').'>';
                    } else {
                      $data['fromAddress'] = get_option('zmail_integ_from_email_id');
                    }
                    $data['subject'] = $subject;
                    $data['content'] = $message;
                    $toAddresses = implode(',' ,$to);
                    $data['toAddress'] = $toAddresses;
                    $urlUsingRefreshToken ='https://accounts.zoho.'.get_option('zmail_integ_domain_name').'/oauth/v2/token?refresh_token='.get_option('zmail_refresh_token').'&grant_type=refresh_token&client_id='.get_option('zmail_integ_client_id').'&client_secret='.get_option('zmail_integ_client_secret').'&redirect_uri='.admin_url().'admin.php?page=zmail-integ-settings&scope=VirtualOffice.messages.CREATE,VirtualOffice.accounts.READ';
                    $bodyAccessTok = wp_remote_retrieve_body(wp_remote_post( $urlUsingRefreshToken));
                    $respoJs = json_decode($bodyAccessTok);
                    update_option('zmail_access_token',$respoJs->access_token);
                    $urlToSend = 'https://mail.zoho.'.get_option('zmail_integ_domain_name').'/api/accounts/'.get_option('zmail_account_id').'/messages';
                    if(!empty($attachments)){
                        $data['attachments'] = $attachments;
                    }  
                    if( $content_type == 'text/html' ) {
                      $data['mailFormat'] = 'html';
                    } else {
                      $data['mailFormat'] = 'plaintext';
                    }   
                    $headers1 = array(
                             'Authorization' => 'Zoho-oauthtoken '.get_option('zmail_access_token'),
                             'Content-Type' => 'application/json'
                           );
                    
                    $data_string = json_encode($data);
                    $args = array(
                             'body' => $data_string,
                             'headers' => $headers1,
                             'method' => 'POST'
                          );
                    $responseSending = wp_remote_post( $urlToSend, $args );
                    $http_code = wp_remote_retrieve_response_code($responseSending);
                    if($http_code == '200') {
                      return true;
                    }
                    return false;
    
      }
    }

    Help please. Do we need to change the $mailer?

    #26764
    katw
    Participant

    I have 100% confirmed it is the assumed $mailer using PHPmail for email sending that is the issue.

    How do I modify the hook for $mailer = ZOHO mail?

    Thanks

    Kat

    #26765
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    • This reply was modified 5 years, 8 months ago by Ally. Reason: Typo
    #26978
    katw
    Participant

    Worked like a treat. Thanks Ally.

    Close ticket

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy