【问题标题】:How to add a body background color to php, html email template如何为 php、html 电子邮件模板添加正文背景颜色
【发布时间】:2023-04-09 05:30:01
【问题描述】:

所以我有一个以白色正文背景发送的确认电子邮件模板,但我想将其设为灰色,但我不确定如何将其添加到以下电子邮件功能所在的 php 文件中

$headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
$headers .= "Reply-To: " . $from_email . "\r\n";
//$headers  .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
$headers = apply_filters( 'give_admin_donation_notification_headers', $headers, $payment_id, $payment_data );

$attachments = apply_filters( 'give_admin_donation_notification_attachments', array(), $payment_id, $payment_data );

$message = give_get_donation_notification_body_content( $payment_id, $payment_data );

我可以在标题后的任何位置添加一个 html 正文颜色标签吗?

这是 give_get_donation_notification_body_content 中的代码

function give_get_donation_notification_body_content( $payment_id = 0, $payment_data = array() ) {

$user_info = maybe_unserialize( $payment_data['user_info'] );
$email     = give_get_payment_user_email( $payment_id );

if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) {
    $user_data = get_userdata( $user_info['id'] );
    $name      = $user_data->display_name;
} elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) {
    $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
} else {
    $name = $email;
}

$gateway = give_get_gateway_admin_label( get_post_meta( $payment_id, '_give_payment_gateway', true ) );

$default_email_body = esc_html__( 'Hello', 'give' ) . "\n\n";
$default_email_body .= esc_html__( 'A donation has been made.', 'give' ) . "\n\n";
/* translators: %s: form plural label */
$default_email_body .= sprintf( esc_html__( '%s sold:', 'give' ), give_get_forms_label_plural() ) . "\n\n";
$default_email_body .= esc_html__( 'Donor:', 'give' ) . ' ' . html_entity_decode( $name, ENT_COMPAT, 'UTF-8' ) . "\n";
$default_email_body .= esc_html__( 'Amount:', 'give' ) . ' ' . html_entity_decode( give_currency_filter( give_format_amount( give_get_payment_amount( $payment_id ) ) ), ENT_COMPAT, 'UTF-8' ) . "\n";
$default_email_body .= esc_html__( 'Payment Method:', 'give' ) . ' ' . $gateway . "\n\n";
$default_email_body .= esc_html__( 'Thank you', 'give' );

$email = give_get_option( 'donation_notification' );
$email = isset( $email ) ? stripslashes( $email ) : $default_email_body;

$email_body = give_do_email_tags( $email, $payment_id );

return apply_filters( 'give_donation_notification', wpautop( $email_body ), $payment_id, $payment_data );

}

【问题讨论】:

  • give_get_donation_notification_body_content() 包含电子邮件内容,其中应包含您需要更改的html
  • 对不起,我不关注。我在不同的文档中找到了函数 give_get_donation_notification_body_content( $payment_id = 0, $payment_data = array() ) { 但它不包含 标记,所以我可以添加我的 stile
  • 可以添加函数give_get_donation_notification_body_content(..,..)的代码
  • 我已经编辑了我的问题,请检查一下。
  • 看起来不像实际发送 html 格式的电子邮件

标签: php html css html-email


【解决方案1】:

您的问题是“如何在正文电子邮件中添加 html 颜色标签”,不是吗?

根据我的经验,使用 PHP 以 html 格式发送电子邮件。 首先我们需要从我们的客户那里知道:

  1. 您的客户端操作系统:win、linux、android、mac、iphone 等

  2. 您的客户端电子邮件应用程序:thunderbird、firefox 浏览器、chrome 浏览器、Ms Outlook 等

  3. 您的客户端 EMAIL 服务器:gmail、yahoo 等

每件事都有不同的问题。要了解更多信息,您可以阅读此链接https://css-tricks.com/using-css-in-html-emails-the-real-story/

所以您能做的最好的事情就是“尽可能为所有电子邮件客户端设计最佳外观”

你的问题是

  1. “我可以在电子邮件模板中添加背景颜色吗?”

回答:可以

  1. “我可以在 HTML 标签中添加 Class/ID,然后使用 CSS 设置样式吗?”

回答:是的,你可以,但是有几个电子邮件服务器不允许你像 gmail 那样这样做

  1. “我可以给 设置样式,并在 中写一些东西,或者只写 吗?”

回答:可以,但是不要写、、,直接用div或者你的内容开头。

所以最好的方法是使用内联样式设置每个 html 标签的样式

$default_email_body = "<div style=\"background-color: grey;\">
<h1 style=\"color: red;\">email title</h1>
<p style=\"font-size: 8px;\">body emailllllllllllllllllll</p>
</div>";

尝试发送该 HTML

【讨论】:

    猜你喜欢
    • 2017-11-22
    • 2012-03-18
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2020-07-07
    • 2013-02-22
    • 2019-09-03
    • 1970-01-01
    相关资源
    最近更新 更多