【问题标题】:Sending my html email发送我的 html 电子邮件
【发布时间】:2015-03-19 18:06:11
【问题描述】:

我知道到处都有很多关于这个主题的信息,但我似乎在兜圈子,非常感谢任何帮助。我正在尝试发送带有一些内联 css 的简单 html 电子邮件。电子邮件似乎没有到达...

<?php
// Email the user their activation link
        $to = "name@website.com";                            
        $from = "me@website.com";
        $subject = 'Test HTML Email';

$headers = "";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = '<div style="padding:10px; background:#000; font-size:46px; font-weight: 900; color:#fff; ">
        My Website
      </div>
      <div style="padding:24px; font-size:17px; background:#DCDCDC  ; ">
        This is a message sent from my website
        <br>
        <br>
        <a href="http://www.mywebsite.com">Login in to your account</a>
        <br>
        <br>
      </div>';

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

【问题讨论】:

  • 试试:$isMailed = mail($to, $subject, $message, $headers);回声 $isMailed;这是返回真还是假?并添加 $headers .= "From: yourmail.com \r\n";刚看到,但是本在我前面..
  • 发件人未定义。
  • 我倾向于建议不要使用mail(),而只是使用一个像样的库(PHPMailer、SwiftMailer)。这也可以防止安全问题,例如标头注入。

标签: php css email


【解决方案1】:

重写这段代码:

$headers = "";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

到这里:

$headers = "";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "To: ". $to. "\r\n";
$headers .= "From: ". $from;

【讨论】:

  • 非常感谢,这是我尝试的第一件事,它立即奏效。非常感谢。
【解决方案2】:

尝试添加这个:

$headers .= "From: $from" . "\r\n" .
            "Reply-To: $from" . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

【讨论】:

    猜你喜欢
    • 2011-03-30
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 2016-11-23
    • 2015-06-07
    • 2012-12-29
    • 1970-01-01
    相关资源
    最近更新 更多