如何使用wp_mail()显示邮件头中的图像

时间:2016-08-17 作者:Dinesh

如何在电子邮件标题中显示图像。我在下面尝试过,它在gmail中没有显示图像。请任何人帮我解决这个问题。提前谢谢。

    $to = $_REQUEST[\'userEmail\'];
    $firstName = $_REQUEST[\'firstName\'];
    $lastName = $_REQUEST[\'lastName\'];
    $email = $_REQUEST[\'email\'];
    $question = $_POST[\'message\'];
    $subject = \'Test Email\';
    $message = "<html><head><img src=\'http://192.168.1.157/Shop/wp-content/uploads/2016/07/image_nmae.png\'/></head>"
            . "<body><h1>Visitor Information</h1>"
            . "<p>Visitor Information: Fist Name:&nbsp;&nbsp;".$firstName."&nbsp;&nbsp; Last Name:&nbsp;&nbsp; ".$lastName."</p>"
            . "<p>Email:&nbsp;&nbsp;".$email."</p><p>Question:&nbsp;&nbsp;".$question."</p></body></html>";
    $headers = array(\'Content-Type: text/html; charset=UTF-8\');
    $mailSend = wp_mail($to, $subject, $message,$headers);

2 个回复
SO网友:butlerblog

电子邮件标题与<head> HTML文档(即使该文档是电子邮件)。所以问题不应该是如何在电子邮件标题中显示图像,因为答案是你不能。

其次,HTML文档也是如此。这个<head> 第(1)节<img> 标签当前位于OP中)用于保存有关文档的信息,其中包含的内容将不会显示。

<img> 中的标记<head> 不会显示位置,问题只是HTML格式错误。要显示<img> 必须在<body> 标记某处。

$to = $_REQUEST[\'userEmail\'];
$firstName = $_REQUEST[\'firstName\'];
$lastName = $_REQUEST[\'lastName\'];
$email = $_REQUEST[\'email\'];
$question = $_POST[\'message\'];
$subject = \'Test Email\';
$message = "<html><head></head><body><img src=\'http://192.168.1.157/Shop/wp-content/uploads/2016/07/image_nmae.png\'/>"
        . "<h1>Visitor Information</h1>"
        . "<p>Visitor Information: Fist Name:&nbsp;&nbsp;".$firstName."&nbsp;&nbsp; Last Name:&nbsp;&nbsp; ".$lastName."</p>"
        . "<p>Email:&nbsp;&nbsp;".$email."</p><p>Question:&nbsp;&nbsp;".$question."</p></body></html>";
$headers = array(\'Content-Type: text/html; charset=UTF-8\');
$mailSend = wp_mail($to, $subject, $message,$headers);

SO网友:Joseph Seyi Taiwo

您可以添加$headers 在表单之前。还分析$headers 像这样

$headers .= 
"Content-Type: text/html; 
charset=UTF-8\\r\\n";

相关推荐

Cron not sending wp-mail()

我对cron计划功能有问题,它不想用wp_mail() 作用This is my code:它被放置在函数中。php<?php add_filter(\'cron_schedules\', \'add_review_invites_schedule\'); function add_review_invites_schedule($schedules){ $schedules[\'send_review_invites_interva