繁体   English   中英

用php发送html邮件

[英]send html mail with php

我有php代码可以像这样发送邮件:

    <?php
    $to='123.123@gmail.com';
    $subject = 'testing';
    //create a boundary string. It must be unique
    $random_hash = md5(date('r', time()));
    //define the headers we want passed. Note that they are separated with \r\n
    $headers = "From: 123@gmail.com\r\nReply-To: 123@gmail.com";
    //add boundary string and mime type specification
    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
    //define the body of the message.
    ob_start(); //Turn on output buffering
    ?>
    --PHP-mixed-<?php echo $random_hash; ?>
    Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
    --PHP-alt-<?php echo $random_hash; ?>
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    --PHP-alt-<?php echo $random_hash; ?>
    Content-Type: text/html; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    <?php
//html content
    include ("http://10.*.*.*/maps/tes.php");
    ?>

    --PHP-alt-<?php echo $random_hash; ?>--

    --PHP-mixed-<?php echo $random_hash; ?>
    #Content-Type: application/html; name="racing_mkios_data_wok_sbt_201403.html"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment

    --PHP-mixed-<?php echo $random_hash; ?>--

    <?php
    //copy current buffer contents into $message variable and delete current output buffer
    $message = ob_get_clean();
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>

它发送给我html代码而不是内容。 我的代码有什么错? 我一直在搜寻一个小时,但仍找不到答案..................................... ...........................

尝试将标题内容类型更改为text / html。 切换此行:

 $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

至:

 $headers .= "\r\nContent-Type: text/html; boundary=\"PHP-mixed-".$random_hash."\"";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM