php 如何更改文本的颜色和粗体

ylamdve6  于 2023-01-29  发布在  PHP
关注(0)|答案(3)|浏览(159)

如何更改发送到电子邮件地址的这封邮件中的文本的颜色和粗体?

'The coupon code "%s" has been applied by a customer'

链接到原始内容

// For all Woocommerce versions (since 3.0)
add_action( 'woocommerce_checkout_update_order_meta', 'custom_email_for_orders_with_applied_coupon' );
function custom_email_for_orders_with_applied_coupon( $order_id ){
    $order = wc_get_order( $order_id );

    $used_coupons = $order->get_used_coupons();

    if( ! empty($used_coupons) ){
        foreach ( $used_coupons as $coupon_code ) {
            $coupon    = new WC_Coupon( $coupon_code ); // WC_Coupon Object
            $recipient = $coupon->get_meta('email_recipient'); // get recipient

            if( ! empty($recipient) ) {
                $subject = sprintf( __('Coupon "%s" has been applied'), $coupon_code );
                $content = sprintf( __('The coupon code "%s" has been applied by a customer'), $coupon_code );
                wp_mail( $recipient, $subject, $content ); // Send email
            }
        }
    }
}

我正在尝试为电子邮件回复设置css或其他样式效果
enter image description here

bkkx9g8r

bkkx9g8r1#

你试过HTML吗?你可以像这样添加内联css:<span style="color:red">word</span>
如果HTML主体不是wp_mail的默认值(实际情况如此),则应添加以下标题:

$to = 'sendto@example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');

wp_mail( $to, $subject, $body, $headers );
3wabscal

3wabscal2#

更改此行:

$content = sprintf( __('The coupon code "%s" has been applied by a customer'), $coupon_code );

致:

$content = sprintf( __('<span style="color:green;">The</span> coupon code <span style="color:green;font-weight:bold;">"%s"</span> has been applied by a customer'), $coupon_code );
hmae6n7t

hmae6n7t3#

更改此内容:

`$subject = sprintf( __('Coupon "%s" has been applied'), $coupon_code )`;

对此:

$content = sprintf( __('<strong style="color: red;">The coupon code "%s"</strong> has been applied by a customer'), $coupon_code );

相关问题