wp_mail wordpress html,样式不适用

问题描述 投票:0回答:3

我正在尝试从我的 WordPress 插件发送邮件,但当我检索它时,它没有样式或图像。

我正在这样做:

<?php
$headers = array(
    "From: Enara <[email protected]>",
    "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 代码),将内容类型更改为

iso
,并制作了 wp 过滤器
wp_mail_content_type
'text/html' .

图像也不起作用。

如果我使用开发工具调试收到的电子邮件,我会看到:

<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
php css wordpress styles html-email
3个回答
9
投票

如果能把你的使用方法的代码贴出来就更好了

wp_mail_content_type

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

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

wp_mail( '[email protected]', 'The subject', '<div>The message</div>' );

0
投票

尝试添加

add_filter('wp_mail_content_type',create_function('', 'return "text/html"; '));

默认情况下

wp_mail()
返回
text/plain
内容。

您可以使用 WordPress 的 wp_mail() 函数从 WordPress 网站发送电子邮件。但是,默认内容类型是“text/plain”,不允许使用 HTML。如果您想发送 HTML 电子邮件,则需要使用“wp_mail_content_type”过滤器将电子邮件的内容类型设置为“text/html”。

来源:如何从 WordPress 发送 HTML 电子邮件

编辑

问题似乎与邮件客户端 HTML 内容的呈现有关。


0
投票
$to = '[email protected]';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');

wp_mail( $to, $subject, $body, $headers );
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.