如何使用联系表 7 发送消息正文中的 HTML 内容?
How to send HTML content in message body using contact form 7?
我想使用联系表 7 发送 HTML 内容,但是 HTML 代码不起作用直接在电子邮件中发送 HTML 标签。那么如何使用挂钩或任何方式发送此类消息?
我正在使用挂钩 "wpcf7_posted_data" 在正文中附加额外的 HTML 标签。
我想在发送电子邮件之前发送额外的 HTML 格式数据。
function action_wpcf7_posted_data( $array ) {
$html .= '<table>';
$html .='<tr><td>'.$product->get_Name().'</td></tr>';
$html .='<tr><td>'.$display.'</td></tr>';
$html .='<tr><td>Qty : '.$ProductQty.'</td></tr>';
$html .= '</table>';
$value = $array['message'];
if( !empty( $value ) ){
$array['message'] = $value."<br><br>".$html;
}
return $array;
}
add_filter( 'wpcf7_posted_data', 'action_wpcf7_posted_data', 10, 1 );
您不需要用户自己在表单中插入 HTML。所以您需要在 MAIL TAB 本身的表单中设置发送邮件的布局,并检查邮件正文字段下方的 "Use HTML content type"。
您可以撰写 HTML,但请注意邮件协议和客户端不会读取所有 HTML 标签甚至所有 CSS。
检查此 link 如何创建 HTML 电子邮件正文消息:https://www.campaignmonitor.com/dev-resources/guides/coding-html-emails/
这允许 CSS:https://www.campaignmonitor.com/css/
您也可以将表格发送至其他邮箱,勾选使用邮件(2)
"is an additional mail template often used as an autoresponder".
检查 Contact Form 7 文档:https://contactform7.com/setting-up-mail/
问候。
H
如果您尝试将数据附加到 Contact Form 7 电子邮件 HTML。下面的代码将做到这一点。但是,您似乎正在使用一些其他变量,我不确定您是从哪里得到它们的。所有提交的表单字段都将在下面我的函数中的 $posted_data
中。您可以在字段存在时触发该过程,或者每次都 运行 它。您还可以使用 global $product
并获取变量来完成您的 table。
add_action( 'wpcf7_before_send_mail', 'he_append_to_email_body' );
function he_append_to_email_body( $contact_form ) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
}
if (isset($posted_data['the_field_you_want_to_trigger_this'])) { // Check that your field is present in your form.
/**
* ToDo:
* Get your product and display and other variables here to put into the table.
*/
$html = '<table>';
$html .='<tr><td>'.$product->get_Name().'</td></tr>';
$html .='<tr><td>'.$display.'</td></tr>';
$html .='<tr><td>Qty : '.$ProductQty.'</td></tr>';
$html .= '</table>';
// Get the existing output from the CF7 email
$mail = $contact_form->prop( 'mail' );
// Append your data after the existing
$mail['body'] .= $html;
// Update the mail
$contact_form->set_properties(array('mail' => $mail));
}
return;
}
我想使用联系表 7 发送 HTML 内容,但是 HTML 代码不起作用直接在电子邮件中发送 HTML 标签。那么如何使用挂钩或任何方式发送此类消息?
我正在使用挂钩 "wpcf7_posted_data" 在正文中附加额外的 HTML 标签。 我想在发送电子邮件之前发送额外的 HTML 格式数据。
function action_wpcf7_posted_data( $array ) {
$html .= '<table>';
$html .='<tr><td>'.$product->get_Name().'</td></tr>';
$html .='<tr><td>'.$display.'</td></tr>';
$html .='<tr><td>Qty : '.$ProductQty.'</td></tr>';
$html .= '</table>';
$value = $array['message'];
if( !empty( $value ) ){
$array['message'] = $value."<br><br>".$html;
}
return $array;
}
add_filter( 'wpcf7_posted_data', 'action_wpcf7_posted_data', 10, 1 );
您不需要用户自己在表单中插入 HTML。所以您需要在 MAIL TAB 本身的表单中设置发送邮件的布局,并检查邮件正文字段下方的 "Use HTML content type"。
您可以撰写 HTML,但请注意邮件协议和客户端不会读取所有 HTML 标签甚至所有 CSS。 检查此 link 如何创建 HTML 电子邮件正文消息:https://www.campaignmonitor.com/dev-resources/guides/coding-html-emails/ 这允许 CSS:https://www.campaignmonitor.com/css/
您也可以将表格发送至其他邮箱,勾选使用邮件(2) "is an additional mail template often used as an autoresponder".
检查 Contact Form 7 文档:https://contactform7.com/setting-up-mail/
问候。 H
如果您尝试将数据附加到 Contact Form 7 电子邮件 HTML。下面的代码将做到这一点。但是,您似乎正在使用一些其他变量,我不确定您是从哪里得到它们的。所有提交的表单字段都将在下面我的函数中的 $posted_data
中。您可以在字段存在时触发该过程,或者每次都 运行 它。您还可以使用 global $product
并获取变量来完成您的 table。
add_action( 'wpcf7_before_send_mail', 'he_append_to_email_body' );
function he_append_to_email_body( $contact_form ) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
}
if (isset($posted_data['the_field_you_want_to_trigger_this'])) { // Check that your field is present in your form.
/**
* ToDo:
* Get your product and display and other variables here to put into the table.
*/
$html = '<table>';
$html .='<tr><td>'.$product->get_Name().'</td></tr>';
$html .='<tr><td>'.$display.'</td></tr>';
$html .='<tr><td>Qty : '.$ProductQty.'</td></tr>';
$html .= '</table>';
// Get the existing output from the CF7 email
$mail = $contact_form->prop( 'mail' );
// Append your data after the existing
$mail['body'] .= $html;
// Update the mail
$contact_form->set_properties(array('mail' => $mail));
}
return;
}