Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Forms: allow reply via email in plain text
56 changes: 43 additions & 13 deletions projects/packages/forms/src/contact-form/class-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1112,10 +1112,11 @@ private static function get_raw_compiled_form_data( $feedback_id, $form = null )
*
* @param int $feedback_id - the feedback ID.
* @param Contact_Form $form - the form.
* @param bool $urlencoded - should the response be in urlencoded plain text, or HTML.
*
* @return array $lines
*/
public static function get_compiled_form_for_email( $feedback_id, $form ) {
public static function get_compiled_form_for_email( $feedback_id, $form, $urlencoded = false ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this function returning "HTML" or "urlencoded array" is great and should not land in this format the PR, but it served as a quick demo.

We should be able to get "plain text" and "HTML" versions of form submissions, which then carries it all the way down to how file upload fields, multi line text fields etc get rendered.

Plain text can then be used to render plain text version of the full email as well, for those clients that instruct not to get HTML versions.

Then we can use plain text in emails and just wrap it in urlencode().

$compiled_form = array();
$response = Feedback::get( $feedback_id );

Expand All @@ -1136,25 +1137,32 @@ public static function get_compiled_form_for_email( $feedback_id, $form ) {
* @param Contact_Form $form a copy of this object
*/
$updated_compiled_form = apply_filters( 'jetpack_forms_response_email', $compiled_form, $feedback_id, $form );

if ( $updated_compiled_form !== $compiled_form ) {
$compiled_form = $updated_compiled_form;
} else {
// add styling to the array
// Add styling to the array
foreach ( $compiled_form as $key => $value ) {
$safe_display_label = self::escape_and_sanitize_field_label( $value['label'] );
$safe_display_label = self::maybe_add_colon_to_label( $safe_display_label );
$safe_display_value = self::escape_and_sanitize_field_value( $value['value'] );
$nl = '%0A'; // URLEncoded newlines

if ( ! empty( $safe_display_label ) ) {
$compiled_form[ $key ] = sprintf(
'<p><strong>%1$s</strong><br /><span>%2$s</span></p>',
self::maybe_add_colon_to_label( $safe_display_label ),
$safe_display_value
);
$compiled_form[ $key ] = $urlencoded
? rawurlencode( $safe_display_label ) . $nl . rawurlencode( $safe_display_value ) . $nl . $nl
: sprintf(
'<p><strong>%1$s</strong><br /><span>%2$s</span></p>',
$safe_display_label,
$safe_display_value
);
} else {
$compiled_form[ $key ] = sprintf(
'<p><span>%s</span></p>',
$safe_display_value
);
$compiled_form[ $key ] = $urlencoded
? rawurlencode( $safe_display_value ) . $nl . $nl
: sprintf(
'<p><span>%s</span></p>',
$safe_display_value
);
}
}
}
Expand Down Expand Up @@ -2104,6 +2112,15 @@ public function process_submission() {
__( 'Mark as spam', 'jetpack-forms' )
);

$message_urlencoded = self::get_compiled_form_for_email( $post_id, $this, true );
$reply_mailto_url =
'mailto:' .
rawurlencode( $reply_to_addr ) .
'?subject=' .
rawurlencode( 'Re: ' . $subject ) .
'&body=' .
implode( '', $message_urlencoded );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to check for URL length limits here.


$footer = implode(
'',
/**
Expand All @@ -2130,7 +2147,7 @@ public function process_submission() {
);

$actions = sprintf(
'<table class="button_block" border="0" cellpadding="0" cellspacing="0" role="presentation">
'<table class="button_block" border="0" cellpadding="0" cellspacing="8" role="presentation">
Copy link
Member Author

@simison simison Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this HTML table gets moved to HTML template, and actions becomes more lightweight; either just link tags or URL+label.

Now we're starting to split HTML layout in two different files which isn't great.

<tr>
<td class="pad" align="center">
<a rel="noopener" target="_blank" href="%1$s" data-tracks-link-desc="">
Expand All @@ -2143,10 +2160,23 @@ public function process_submission() {
<![endif]-->
</a>
</td>
<td class="pad" align="center">
<a rel="noopener" target="_blank" href="%3$s" data-tracks-link-desc="">
<!--[if mso]>
<i style="mso-text-raise: 30pt;">&nbsp;</i>
<![endif]-->
<span>%4$s</span>
<!--[if mso]>
<i>&nbsp;</i>
<![endif]-->
</a>
</td>
</tr>
</table>',
esc_url( $dashboard_url ),
__( 'View in dashboard', 'jetpack-forms' )
__( 'View in dashboard', 'jetpack-forms' ),
esc_url( $reply_mailto_url ),
__( 'Reply via email', 'jetpack-forms' )
);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Forms: allow reply via email in plain text
Loading