简体   繁体   English

如何为php,html电子邮件模板添加正文背景颜色

[英]How to add a body background color to php, html email template

So I have a confirmation email templates that is being sent with a white body background but I would like to make it gray but I am not sure how to add this in the php file where the email function below is 所以我有一个确认电子邮件模板,正在发送白色背景但我想让它变灰但我不知道如何在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 );

Can I just add an html body color tag anywhere after the header? 我可以在标题后的任何地方添加一个html正文颜色标记吗?

This is the code in give_get_donation_notification_body_content 这是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 );

} }

Your question is "How to add html color tags in body email", isnt? 你的问题是“如何在正文电子邮件中添加html颜色标签”,不是吗?

in my experience send email as html using PHP. 根据我的经验,使用PHP发送电子邮件为html。 first We need to know from our client: 首先,我们需要了解客户:

  1. your client OS : win, linux, android, mac, iphone etc 你的客户端操作系统:win,linux,android,mac,iphone等

  2. your client email application: thunderbird, firefox browser, chrome browser, Ms outlook, etc 您的客户端电子邮件应用程序:thunderbird,firefox浏览器,chrome浏览器,Ms outlook等

  3. you client EMAIL server: gmail, yahoo, etc 你的客户端EMAIL服务器:gmail,yahoo等

everything have different issue. 一切都有不同的问题。 to know more about this, you can read this link https://css-tricks.com/using-css-in-html-emails-the-real-story/ 要了解更多信息,请阅读此链接https://css-tricks.com/using-css-in-html-emails-the-real-story/

so the best you can do is "Design the best looks for all email client as possible as you can" 所以你能做的最好的事情是“尽可能为所有电子邮件客户端设计最好的外观”

and your question is 而你的问题是

  1. "Can i add background color in email template?" “我可以在电子邮件模板中添加背景颜色吗?”

Answer: yes you can 答:是的,你可以

  1. "Can i add Class/ID in HTML tag then use CSS for styling them?" “我可以在HTML标签中添加Class / ID,然后使用CSS来设置样式吗?”

Answer: Yes, you can, but several email server will not allow you to doing that like gmail 答:是的,你可以,但是有几个电子邮件服务器不允许你这样做,就像gmail一样

  1. "can i styling <*body>, and wrote something in <*head> or maybe just write <*html>?" “我可以造型<* body>,并在<* head>中写一些东西,或者只是写<* html>?”

Answer: Yes, you can, but prevent to write <*html>, <*body>, <*head>, just start with div or your content directly. 答:是的,你可以,但要阻止写<* html>,<* body>,<* head>,直接从div或你的内容开始。

so the best way is styling every html tag with inline style 所以最好的方法是使用内联样式为每个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>";

try to send that HTML 尝试发送该HTML

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM