【问题标题】:Why is the HTML not being interpreted in this e-mail?为什么此电子邮件中没有解释 HTML?
【发布时间】:2013-08-14 22:39:36
【问题描述】:

我正在使用 WAMP 本地运行一个网站,并安装了测试邮件服务器工具作为邮件服务器(它所做的只是将邮件保存为 .eml 文件)。我尝试使用 Lotus Notes 和 gmail(Web 界面)打开邮件,但两者都不解释 HTML,例如,他们没有可点击的链接,而是拥有 <a href='localhost'>click here</a> 标题我犯了错误吗?

这是我正在使用的代码

$to = 'bepusslai@fakeinbox.com';
$from = 'From: tester1@localhost.com';
$subject = 'this is a test';
$message = '<html><head></head><body>Hello. Please follow <a href="http://localhost/proc.php?uid=45ab3">this link</a> to activate your account.'
    ."r\n".'<a href="http://localhost/proc.php?uid=45ab3"><img src="images/ActivateButton.gif" alt="activate button" />
    </body></html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; utf-8' . "\r\n";
$headers .= 'From: testk1@localhost.com' . "\r\n";
mail($to, $subject, $message, $from, $headers);

顺便说一句,我被困在没有邮件服务器的问题上,因为 WAMP 没有附带邮件服务器,而且我对有人推荐的另一个问题感到满意 Test Mail Server Tool。我愿意使用其他的,因为它似乎不受欢迎。

【问题讨论】:

    标签: php email wamp


    【解决方案1】:

    如果您参考文档中的 the docs 和示例,您将看到 From 信息不是 mail() 的单独参数,而是包含在附加标头信息中。

    bool 邮件 ( 字符串 $to , 字符串 $subject , 字符串 $message [, 字符串 $additional_headers [, string $additional_parameters ]] )

    从对 mail() 的调用中删除您的 $from 参数。

    mail($to, $subject, $message, $headers);
    

    【讨论】:

    • 我使用测试邮件服务器工具,我认为它很棒:使用起来非常简单。
    • 有趣的是错误是如何表现出来的。我在使用 PHP 时遇到的一个主要问题是,当出现问题时,您不能完全确定问题出在代码的哪个位置。
    • error_reporting(E_ALL); ini_set('display_errors', '1'); 在 php 的顶部添加这两行(在开发期间)将输出所有错误。您还需要经常 echo 或 print_r 您的变量以查看它们发生了什么。祝你好运;)
    【解决方案2】:

    看看这个例子,它对我有用:

    <? 
    //change this to your email. 
    $to = "m@maaking.com"; 
    $from = "m2@maaking.com"; 
    $subject = "Hello! This is HTML email"; 
    
    //begin of HTML message 
    $message = "<html> 
       <body bgcolor=\"#DCEEFC\"> 
    <center> 
        <b>Looool!!! I am reciving HTML email......</b> <br> 
        <font color=\"red\">Thanks dud!</font> <br> 
        <a href=\"http://www.test.com/\">* test.com</a> 
    </center> 
      <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine 
      </body> 
       </html>"; 
    //end of message 
    
    // To send the HTML mail we need to set the Content-type header. 
    $headers = "MIME-Version: 1.0rn"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1rn"; 
    $headers  .= "From: $from\r\n"; 
    //options to send to cc+bcc 
    //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]"; 
    //$headers .= "Bcc: [email]email@example.cXom[/email]"; 
    
    // now lets send the email. 
    mail($to, $subject, $message, $headers); 
    
    echo "Message has been sent....!"; 
     ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      • 2011-08-27
      • 2014-01-08
      • 1970-01-01
      • 2015-12-19
      • 2014-12-24
      相关资源
      最近更新 更多