【问题标题】:email contents not showing电子邮件内容未显示
【发布时间】:2012-01-03 09:49:41
【问题描述】:

我的 PHP 应用程序发送的一些电子邮件存在问题。

收到的电子邮件是空白的,它们都被发送到特定地址。这些电子邮件也抄送到我可以控制的地址,并且它们都被正确接收。所有电子邮件均以 HTML 格式发送。

我无法控制这些电子邮件发送到的远程电子邮件地址,但我 100% 确信它们会通过某种 M$ 交换垃圾邮件过滤器。会不会是过滤器导致数据丢失?

对此的任何其他想法都会很棒!

【问题讨论】:

    标签: php email html-email


    【解决方案1】:

    您说所有电子邮件都是以 HTML 格式发送的。您可能需要发送纯文本以配合它 - 以迎合那些不支持 HTML 的电子邮件客户端。 http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php.

    这是上面链接的复制粘贴:

    <?php
    //define the receiver of the email
    $to = 'youraddress@example.com';
    //define the subject of the email
    $subject = 'Test HTML email';
    //create a boundary string. It must be unique
    //so we use the MD5 algorithm to generate a random hash
    $random_hash = md5(date('r', time()));
    //define the headers we want passed. Note that they are separated with \r\n
    $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
    //add boundary string and mime type specification
    $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
    //define the body of the message.
    ob_start(); //Turn on output buffering
    ?>
    --PHP-alt-<?php echo $random_hash; ?> 
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit
    
    Hello World!!! 
    This is simple text email message. 
    
    --PHP-alt-<?php echo $random_hash; ?> 
    Content-Type: text/html; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit
    
    <h2>Hello World!</h2>
    <p>This is something with <b>HTML</b> formatting.</p>
    
    --PHP-alt-<?php echo $random_hash; ?>--
    <?
    //copy current buffer contents into $message variable and delete current output buffer
    $message = ob_get_clean();
    //send the email
    $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 格式显示。这是我尝试的第一件事:s
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多