【问题标题】:PHP not sendig HTML template to emailPHP没有将HTML模板发送到电子邮件
【发布时间】:2020-08-16 19:47:20
【问题描述】:

我的问题是,当您注册用户时,会生成发送到电子邮件的随机代码,我为包含基本文本和样式的电子邮件创建了一个模板,此电子邮件仅更改带有生成代码的基本链接。所以一切都应该按我的意思工作,但目前在注册期间会收到电子邮件,但没有我提供的样式。代码如下。

$to = $email;
$subject = "Registration Confirmation";

$link = "<a href='".DIR."/activation?x=$latest_id&y=$activasion'>".DIR."/activation?x=$latest_id&y=$activasion</a>";

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

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

$message = file_get_contents("inc/user_register.html");
$message = str_replace('[link]', $link, $message);

mail($to, $subject, $message, $headers);
header("location: /login?action=joined");

【问题讨论】:

    标签: php mysql email html-email


    【解决方案1】:

    您在第一个标题[] 处缺少 \n。您也可以尝试这种方式设置标题。

    // To send HTML mail, the Content-type header must be set
    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'Content-type: text/html; charset=iso-8859-1';
    
    // Additional headers
    $headers[] = 'To: Mary <mary@example.com>, Kelly <kelly@example.com>';
    $headers[] = 'From: Birthday Reminder <birthday@example.com>';
    $headers[] = 'Cc: birthdayarchive@example.com';
    $headers[] = 'Bcc: birthdaycheck@example.com';
    
    // Mail it
    mail($to, $subject, $message, implode("\r\n", $headers));
    
    

    【讨论】:

    • 像您发送的一样。但仍然不显示样式'
    • 在电子邮件中读取为 Content-Type: text/html 但它不显示 html 样式..
    【解决方案2】:

    问题已解决

    我使用的是来自谷歌字体网站的导入字体。我已将其从样式中删除,并按我想要的方式工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-24
      • 2016-11-03
      • 2010-11-29
      • 2011-04-12
      • 2013-06-22
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多