在wp_mail函数wordpress中添加html [英] add html in wp_mail function wordpress

查看:57
本文介绍了在wp_mail函数wordpress中添加html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在wordpress中创建了一个注册表,但是我在电子邮件确认中遇到了问题,我试图在正文中添加一些html,但是我做错了什么,您能帮我吗?
这是我在functions.php中的代码的一部分,是将电子邮件发送给用户的代码:

i have created a register form in wordpress but i have a problem with the email confirmation, i'm trying to add some html in the body but i made something wrong, can you help me? this is part of my code in functions.php, is the code that send the email to user:

if ( $user_id && !is_wp_error( $user_id ) ) {
        $code = sha1( $user_id . time() );
        $activation_link = add_query_arg( array( 'key' => $code, 'user' => $user_id ),          get_permalink(168));
        add_user_meta( $user_id, 'has_to_be_activated', $code, true );

        wp_mail( $email, 'BLOOOGERS Activación cuenta', '<img src="..."> <br /> <br />Bienvenido a nuestra comunidad, este es el link para que actives tu cuenta:<br /> <br />' . $activation_link );

        add_filter( 'wp_mail_content_type', 'set_html_content_type' );
        function set_html_content_type() {
            return 'text/html';
        }

    }


推荐答案

这非常简单,但是在调用 wp_mail()

This is very easy but add filter code before call wp_mail()

    add_filter('wp_mail_content_type', function( $content_type ) {
                return 'text/html';
    });

    wp_mail( 'me@example.net', 'The subject', '<div>The message</div>' );

这篇关于在wp_mail函数wordpress中添加html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆