• Resolved schmeee

    (@schmediaaolcom)


    Hi! I’m using CF7 plus Conditional Fields for CF7 to deliver a nifty branching intake for potential home buyer leads. At this point in the process, I’d like to add several custom meta fields to the resulting email’s html head, per the following structural guidelines from my realtor’s CRM partner:

    —————————————————-
    Embedding lead metadata

    Following this specification is easy: simply embed key lead information in your lead emails using HTML meta tags. For example, an email that contains lead information should contain header fields as follows:

    <!DOCTYPE html … >
    <html xmlns= … >
    <head>

    <meta name=”lead_information_version” content=”1.0″ />
    <meta name=”lead_source” content=”Realtor.com” />
    <meta name=”lead_type” content=”Buyer” />
    <meta name=”lead_name” content=”John Smith” />
    <meta name=”lead_email” content=”jsmith@gmail.com” />
    <meta name=”lead_phone” content=”703-555-1212″ />

    </head>
    <body>

    </body>
    </html>
    ————————————-

    I tried adding the relevant metadata to the “Additional Headers” field of the form’s ‘MAIL’ tab … but that adds the metadata to the email header not the (further down the document) <html><head> (test email below for your reference, comments in BOLD):

    ————————————-
    Delivered-To: **SNIPPED for privacy**
    Received: by 2002:a59:a768:0:b0:2ae:67b6:7de2 with SMTP id z8csp3854610vqs;
    Fri, 29 Apr 2022 08:37:22 -0700 (PDT)

    **REDACTED lotsa security-related header stuff**

    Subject: Attn: Buyer Has No Agent Yet
    **REDACTED for privacy**
    Date: Fri, 29 Apr 2022 15:37:21 +0000
    From: Do Not Reply <wordpress@myziphome.com>
    Message-ID: <**REDACTED for privacy**>
    X-Mailer: PHPMailer 6.5.3 (https://github.com/PHPMailer/PHPMailer)

    **THE NEW STRUCTURED METADATA SHOWS UP HERE …**
    lead_information_version: 1.0
    lead_source: myziphome.com
    lead_type: buyer
    lead_name: **REDACTED for privacy**
    lead_email: **REDACTED for privacy**
    lead_phone: **REDACTED for privacy**
    MIME-Version: 1.0
    Content-Type: multipart/alternative; boundary=”b1_QI3jzOZAh9u8vppAW0ukf2psCNKxBFKbn0vWU5vSfe0″
    Content-Transfer-Encoding: 8bit
    **REDACTED for privacy**

    –b1_QI3jzOZAh9u8vppAW0ukf2psCNKxBFKbn0vWU5vSfe0
    Content-Type: text/plain; charset=us-ascii

    Buyer Has No Agent Yet
    ____________
    Name: **REDACTED for privacy**
    Email: **REDACTED for privacy**
    Phone: **REDACTED for privacy**
    ____________
    –b1_QI3jzOZAh9u8vppAW0ukf2psCNKxBFKbn0vWU5vSfe0
    Content-Type: text/html; charset=us-ascii

    <!doctype html>
    <html xmlns=”http://www.w3.org/1999/xhtml&#8221; dir=”ltr” lang=”en-US”>
    <head>
    <title>Attn: Buyer Has No Agent Yet</title>
    **… BUT I NEED IT TO SHOW UP HERE**
    </head>
    <body>
    <p>Buyer Has No Agent Yet<br />
    ____________<br />
    Name: **REDACTED for privacy**<br />
    Email: **REDACTED for privacy**<br />
    Phone: **REDACTED for privacy**</p>
    <p>____________</p>
    </body>
    </html>

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    You can use the wpcf7_mail_html_header filter hook for the purpose.

    Thread Starter schmeee

    (@schmediaaolcom)

    Thanks very much! Is there any sort of document with a code example for working with the wpcf7_mail_html_header? I’m not skilled enough at working with filters to just look at the source in hookr.io and figure out how to pass the visitor-entered values into a new header that replaces the default header, but from a quick dive I think it’d be something like:

    function filter_wpcf7_mail_html_header ( $doctype_html_html_xmlns_http_www_w3_org_1999_xhtml_head_title_esc_html_this_get_subject_true_title_head_body, $instance ) { 
    	// make filter magic happen here... 
    		// assemble new metas...
    		$addmetas = '
    		<meta name="lead_information_version" content="1.0" />
            <meta name="lead_source" content="https://myziphome.com" />';
    		if ( $this->get( 'subject', true ) == 'Attn: Buyer Has No Agent Yet' ) {
    			$addmetas .= '<meta name="lead_type" content="buyer">;
    			$addmetas .= '<meta name="lead_name" content="' . $instance->get_posted_data( 'second-opinion-buyer-name' ) . '" />;
    			$addmetas .= '<meta name="lead_email" content="' . $instance->get_posted_data( 'second-opinion-buyer-email' ) . '" />;
    			$addmetas .= '<meta name="lead_phone" content="' . $instance->get_posted_data( 'second-opinion-buyer-phone' ) . '" />;
    			
    			}
    		$doctype_html_html_xmlns_http_www_w3_org_1999_xhtml_head_title_esc_html_this_get_subject_true_title_head_body = '<!doctype html> 
    		<html xmlns="http://www.w3.org/1999/xhtml"> 
    		<head> 
    		<title>' . esc_html( $this->get( 'subject', true ) ) . '</title> 
    		' . $addmetas . '
    		</head> 
    		<body> 
    		'
    	return $doctype_html_html_xmlns_http_www_w3_org_1999_xhtml_head_title_esc_html_this_get_subject_true_title_head_body; 
    	}; 
    
    // add the filter 
    add_filter( 'wpcf7_mail_html_header', 'filter_wpcf7_mail_html_header', 10, 2 );

    … am I on the right track? (I’d next add several other cases based on evaluating/matching the passed email SUBJECT.) As I said, I can work with PHP but I’m by no means a filter ninja, so this first draft is based on guesses that could easily (likely!) be all wrong.

    Thanks for your expert assistance, :Benjamin

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    I think you are on the right track.

    Thread Starter schmeee

    (@schmediaaolcom)

    Can I ask (nicely!) for a little help getting my code to work? It’s erring, and I’ve pinned the problem down to my ask for $instance->get_posted_data( 'second-opinion-buyer-name' ) — there is definitely a user-entered field for second-opinion-buyer-name in the form. Is get_posted_data() unavailable within wpcf7_mail_html_header? Any documentation you have w/r/t wpcf7_mail_html_header and/or get_posted_data() would be useful. Thanks in advance for your expert assistance! :Benjamin

    function mzh_addmetas_mail_html_header ( $doctype_html_html_xmlns_http_www_w3_org_1999_xhtml_head_title_esc_html_this_get_subject_true_title_head_body, $instance ) { 
    	// make filter magic happen here... 
    	// assemble new metas...
    	$addmetas = '
    	<meta name="lead_information_version" content="1.0" />
            <meta name="lead_source" content="https://myziphome.com" />
            <meta name="lead_type" content="buyer" />
    	<meta name="lead_name" content="' . $instance->get_posted_data( 'second-opinion-buyer-name' ) . '" />';
    		$doctype_html_html_xmlns_http_www_w3_org_1999_xhtml_head_title_esc_html_this_get_subject_true_title_head_body = '<!doctype html> 
    		<html xmlns="http://www.w3.org/1999/xhtml"> 
    		<head> 
    		<title>' . esc_html( $instance->get( 'subject', true ) ) . '</title> 
    		' . $addmetas . 
    		'
    		</head> 
    		<body> 
    		';
    	return $doctype_html_html_xmlns_http_www_w3_org_1999_xhtml_head_title_esc_html_this_get_subject_true_title_head_body; 
    }
    
    // add the filter 
    add_filter( 'wpcf7_mail_html_header', 'mzh_addmetas_mail_html_header', 10, 2 );
    • This reply was modified 2 years, 10 months ago by schmeee.
    Plugin Author Takayuki Miyoshi

    (@takayukister)

    What other plugins and theme do you use on the site?

    Thread Starter schmeee

    (@schmediaaolcom)

    Multisite Network

    Theme: Generatepress (generatepress.com)

    Plugins:
    8b Home Value
    Akismet
    Black Studio TinyMCE Widget
    Code Snippets
    Conditional Fields for CF7
    Contact Form 7
    Flamingo
    GenerateBlocks
    GP Premium
    iThemes Security
    Jetpack
    MC4WP
    OptinMonster
    Popup Builder
    Really Simple SSL
    Redirection for CF7
    Shortcodes Ultimate
    Simple Custom CSS and JS
    Site Kit by Google
    Stop Media Comment Spamming
    Testimonials Widget Premium
    Widget Logic
    WordPress MU Domain Mapping
    WP Table Builder
    Yoast SEO

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    You seem to have several different contact forms on the site and not all of them seem to have the second-opinion-buyer-name field. On the other hand, the wpcf7_mail_html_header callback function is applied to every contact form submission without checking the existence of second-opinion-buyer-name.

    Also, the second argument for the wpcf7_mail_html_header callback function is the WPCF7_Mail object. A WPCF7_Mail object does not have the get_posted_data() method. It is WPCF7_Submission‘s method.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Want to add several custom META elements to email html head’ is closed to new replies.