样式不正确的wp_mail wordpress html [英] wp_mail wordpress html with style not aplying

查看:70
本文介绍了样式不正确的wp_mail wordpress html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从wordpress插件发送邮件,但是当我检索到它时,它没有样式或图像.

I'm trying to send mail from my wordpress plugin but when I retrieve it, it has not styles or images.

我正在这样做:

<?php
$headers = array(
    "From: Enara <no-reply@enara.es>",
    "MIME-Version: 1.0",
    "Content-type: text/html; charset=UTF-8'"
);
$message = "<html>
    <head>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
    </head>
    <body>
        <div style='background-color: #16a085;'>
            <table>
                <tr><td colspan='2'><img style=\'margin-botton: 20px;\' src='http://enara.litrodeenergia.com/wp-content/uploads/2015/12/enara-white.png' /></td></tr>
                <tr><td colspan='2'>DATOS DE CLIENTE</td></tr>
                <tr><td colspan='2'>$particular</td></tr>
                <tr>
                    <td>Nombre:</td>
                    <td>$nombre<br></td>
                </tr>
                <tr>
                    <td>Apellidos:</td>
                    <td>$apellidos</td>
                </tr>
                <tr>
                    <td>Nif:</td>
                    <td>$nif</td>
                </tr>
                <tr>
                    <td>Tel&eacute;fono:</td>
                    <td>$telefono</td>
                </tr>
            </table>
        </div>
    </body>
</html>";

$result = new stdClass();
$result->mailOk = wp_mail($to, $subject, $message, $headers);

我在脑海中尝试了一个样式代码,删除了html/head/body块(仅发送div html代码),将content-type更改为iso,并使wp过滤器wp_mail_content_type'text/html".

I tried a style code in my head, delete the html/head/body blocks (only send the div html code), changed the content-type to iso, and made the wp filter wp_mail_content_type 'text/html'.

该图像也无法正常工作.

The image don't work also.

如果我使用devtools调试收到的电子邮件,则会看到:

If I debug the recieved email with devtools, I see:

<div style="background-color:#16a085">
<table>
<tbody>
    <tr>
        <td colspan="2"><img src="http://enara.litrodeenergia.com/wp-content/uploads/2015/12/enara-white.png" style=""></td>
    </tr>
    <tr>
        <td colspan="2">DATOS DE CLIENTE</td>
    </tr>
    <tr>
        <td colspan="2">Usuario particular</td>
    </tr>
    <tr>
        <td>Nombre:</td>
        <td>afsd<br>
    </td>
    </tr>
    <tr>
        <td>Apellidos:</td>
        <td></td>
    </tr>
    <tr>
        <td>Nif:</td>
        <td></td>
    </tr>
    <tr>
        <td>Teléfono:</td>
        <td></td>
    </tr>
</tbody>
</table>

以及电子邮件标题:

Received: from server
Received: from 
Subject: Formulario Alta Usuario Web
X-PHP-Script: 
Date: Tue, 23 Feb 2016 11:07:52 +0000
From: 
Message-ID: <53692f88fe04a71fd41ca2475611fa99@
X-Mailer: PHPMailer 5.2.14 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: text/html; charset="UTF-8'"
Content-Transfer-Encoding: 8bit
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - 
X-AntiAbuse: Original Domain - 
X-AntiAbuse: Originator/Caller UID/GID - [500 495] / [47 12]
X-AntiAbuse: Sender Address Domain - 
X-Get-Message-Sender-Via: 
X-Authenticated-Sender: 
X-Source: /usr/bin/php
X-Source-Args: /usr/bin/php /home/public_html/
X-Source-Dir: litrodeenergia.com:/public_html/
Return-Path: 
X-MS-Exchange-Organization-Antispam-Report: IPOnAllowList
X-MS-Exchange-Organization-SCL: -1

推荐答案

如果您放置代码,如何使用wp_mail_content_type

It could be better if you put the code how did you use wp_mail_content_type

您应在调用 wp_mail()之前过滤内容类型,例如:

You should filter content type before call wp_mail() For example:

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天全站免登陆