如何使用php通过插入html发送邮件到邮件内容? [英] How to send mail using php by insert html into mail content?

查看:81
本文介绍了如何使用php通过插入html发送邮件到邮件内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用php通过插入html发送邮件到邮件内容?

How to send mail using php by insert html into mail content ?

我试图插入html代码内部 $ message ,当我测试它的显示错误

I tried to insert html code inner $message, When i test it's show error

像这样解析错误:语法错误,意外的'margin'(T_STRING)

我该怎么办?

<?PHP
include("connect.php");
$email = "test_mail@hotmail.com";    
$to = $email;
$subject = "test subject";
$message = "

<body style="margin: 0; padding: 0;">
    <table border="1" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td>
                <img src="http://i.stack.imgur.com/Jy9QUm.jpg"/>
            </td>
        </tr>
        <tr>
            <td>
                test text
            </td>
        </tr>
    </table>
</body>

";

$headers  = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EXAMPLE <noreply@example.com>' . "\r\n";
$headers .= 'Return-Path: return@example.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn@example.com');
?>


推荐答案

你有一个问题,包装你的 $ body string try this

You have an issue with wrapping your $body string try this

 <?PHP
    include("connect.php");
    $email = "test_mail@hotmail.com";    
    $to = $email;
    $subject = "test subject";
    $message = "

    <body style='margin: 0; padding: 0;'>
        <table border='1' cellpadding='0' cellspacing='0' width='100%'>
            <tr>
                <td>
                    <img src='http://i.stack.imgur.com/Jy9QUm.jpg'/>
                </td>
            </tr>
            <tr>
                <td>
                    test text
                </td>
            </tr>
        </table>
    </body>

    ";

    $headers  = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: EXAMPLE <noreply@example.com>' . "\r\n";
    $headers .= 'Return-Path: return@example.com' . "\r\n";
    mail($to, $subject, $message, $headers, '-freturn@example.com');
    ?>

这篇关于如何使用php通过插入html发送邮件到邮件内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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