通过phpmailer发送html作为附件

时间:2013-08-07 10:20:06

标签: php html email phpmailer

我有html变量,我想通过电子邮件将其作为附件发送。

这是我的代码

$html='
<table  cellpadding="0" cellspacing="0" style=" margin:0 auto;" width="100%">
    <tr>
        <th style="background:#FC3; padding:4px 0;border:1px solid #000; border-bottom:2px solid #000; border-right:2px solid #000;" align="center" valign="middle"><h3 style="font:300 14px verdana; margin:0; text-align:left;text-align:center;">DECLARATION BY THE AGENT</h3></th>
        <th style="background:#FC3; padding:4px 0;border:1px solid #000; border-bottom:2px solid #000; border-right:2px solid #000;" align="center" valign="middle"><h3 style="font:300 14px verdana; margin:0; text-align:left;text-align:center;">DECLARATION BY THE OWNER (The Seller)</h3></th>
    </tr>
    <tr>
        <td width="49%" style="padding:5px 10px;border-right:2px solid #000;">
        <ul style="margin:0; padding:0;">
            <li style="list-style:none; margin:0 0 10px 0;">
                <p style="font:300 12px verdana;float: left; margin:0 5px 0 0;text-align:center;">
                    I hereby declare, I have read and understood the Real Estate Brokers Code of Ethics,

                </p>
            </li>
        </ul></td>
        <td width="49%" style="padding:5px 10px;border-left:1px solid #000;">
        <ul style="margin:0; padding:0;">
            <li style="list-style:none; margin:0 0 10px 0;">
                <p style="font:300 12px verdana;float: left; margin:0 5px 0 0; text-align:center;">
                    I/We hereby declare, we are the Owners of the property as stated below.
                </p>

            </li>

        </ul></td>
    </tr>
</table>';

$mail->AddAttachment($html); // attachment
$mail->Send();

2 个答案:

答案 0 :(得分:0)

我认为你试图发送html而不是试试这个

   $mail->Body = $html;
   $mail->Send();
好的,所以你试图发送它,例如它不起作用?

  $mail->AddAttachment("/var/tmp/file.html");

答案 1 :(得分:0)

AddAttachment()需要一个文件(在文件系统上)

你正在做的事情有AddStringAttachment()功能。请参阅文档:http://docs.redaxo.com/de/4.3.1/class_p_h_p_mailer.html#a92ef5134fdce5bd5fd24a723c508bf2b

试试这个:

$mail->AddStringAttachment($html,"filename.htm","base64","text/html");