【问题标题】:PHP Mail content doesn't display in OutlookPHP 邮件内容不显示在 Outlook 中
【发布时间】:2018-03-22 12:22:06
【问题描述】:

所以我一直在搞乱一点,并继续改进我的 PHP 邮件。一切都很好,有起有落,我终于实现了我想要的。

原来是这样的

<?php 

$headers .= "Content-Type: text/html; charset=UTF-8>\n";
$field_name = $_POST['cf_name'];
$field_age = $_POST['Alter'];
$field_ges = $_POST['Geschlecht'];
$field_gt = $_POST['Gamertag'];
$field_sona = $_POST['Socname'];
$field_rol = $_POST['Rolle'];
$overall_message = 'Vorname: ' . $field_name . '<br>
Alter: ' . $field_age . '<br>
Geschlecht: ' . $field_ges . '<br>
Gamertag: ' . $field_gt . '<br>
SocialClub-Name: ' . $field_sona . '<br>
Rolle: ' . $field_rol;

$subject = 'xRL Anmeldung - ' . $field_rol . ': ' . $field_name;
$body_message = '<!DOCTYPE html>
<html>
<head>
<style>

html, body {
    margin: 0;
    padding: 0;
}

#Mailnap {
    text-align: center;
}

#Mailna {
    text-align: center;
}

.Hgrund {
    margin: 0;
    padding: 0;
    background-color: #DCDCDC;
}

table {
    height: 60px;
    width: 100%;
    border: 0px;
}

.Header {
    height: 60px;
    width: 100%;
    background-color: #1F1F1F;
    border: 0px;
}

.Header th {
    width: 83px;
    height: 60px;
    border: 0px;
    background-color: #DCDCDC;
}

.Header td {
    border: 0px;
    text-align: center;
}

.Header td a {
    fonz-size: 24px;
    text-align: center;
    color: #FFFFFF;
    border-bottom: 3px solid #FFFFFF;
    border-bottom-right-radius: 3px;
    border-bottom-left-radius: 3px;
    text-decoration: none;
}

.Header td a:hover {
    border-bottom: 3px solid #FF0000;
}

.Content {
    width: 98%;
    background-color: #696969;
    margin: 0 1% 0 1%;
    padding: 0;
}

.ContentICBG {
    width: 95%;
    padding: 0;
    margin: 10px auto 10px auto;
    background-color: #DCDCDC;
}

.Content h1 {
    width: 100%;
    margin: 0;
    padding: 0;
    font-size: 24px;
    text-align: center;
    background-color: #D5C4A1;
    color: #000000;
}

.ContentICBG p {
    padding: 10px 10px 10px 10px;
}
</style>
</head>
<body>
<p id="Mailnap"><a href="https://xGamesHub.com/DE/MailFeedback" id="Mailna">Wird diese Mail nicht richtig angezeigt? Klicke bitte hier, und lasse es und wissen!</a></p>

<div class="Hgrund">
<table style="background-color:#DCDCDC;border-bottom:3px solid #DCDCDC;">
 <tr class="Header">
  <th><img src="https://xForigens.com/de-DE/Clans/GTAxRL/xRLN60.png"/></th>
  <td><a href="https://xGamesHub.com/DE/" style="">STARTSEITE</a></td>
  <td><a href="https://xGamesHub.com/DE/Gaming-News/" style="">GAMING NEWS</a></td>
  <td><a href="https://xGamesHub.com/Forum" style="">Forum</a></td>
  <td><a href="https://xForigens.com/de-DE/Clans/SEK1" style="">SEK1</a></td>
  <td><a href="https://xForigens.com/de-DE/Clans/GTAxRL/" style="">xRL</a></td>
 </tr>
</table>

<div class="Content">
 <h1>' . $subject . '</h1>
 <div class="ContentICBG">
  <p>' . $overall_message . '</p>
 </div>
  <h1>Gesendet von: ' . $field_name . '</h1>
</div>

<div style="margin:0;padding:0;background-color:#1F1F1F;border-top:3px solid #DCDCDC;height:30px;width:100%">
 <p style="color:#FFFFFF;text-align:right;font-size:15px;margin:10px 10px 0 0;padding:0;"><a style="color:#FFFFFF;text-decoration:none;" href="https://xForigens.com/de-DE/About">Über</a> | &copy;2017 xForigens</p>
</div>
</div>
</body>
</html>'; 

$mail_to = 'Admin@xForigens.com';
$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
  <script language="javascript" type="text/javascript">
  alert('Danke, wir werden uns in den nächsten 7 Tagen melden.\n\nDamit Du mit am Projekt teilnehmen kannst, musst Du nun mit deinem angegebenen Gamertag, und deinem SocialClub-Name anfragen an Crew & Club senden!')
  window.history.back()
  </script>
<?php
}

else { ?>
  <script language="javascript" type="text/javascript">
  alert('Wenn die Mailfunktion ausfällt, versuche diese erneut zu senden, oder wende Dich an die Administration.')
  window.history.back();
  </script>
<?php
}

?>

一切都很棒。所以我添加了几行,因为我希望显示我自己的地址等,而不是 cgi-mailer@kundenserver.de。

现在看起来像这样

<?php 

$headers .= "Content-Type: text/html; charset=UTF-8>\n";
$headers .= "From: xForigens | xRL<NoReply@xForigens.com>\n";
$headers .= "Reply-To: MailFeedback<Admin@xForigens.com>\n";
$headers .= "X-Mailer: PHP v".phpversion()."\n";
$field_name = $_POST['cf_name'];
$field_age = $_POST['Alter'];
$field_ges = $_POST['Geschlecht'];
$field_gt = $_POST['Gamertag'];
$field_sona = $_POST['Socname'];
$field_rol = $_POST['Rolle'];
$overall_message = 'Vorname: ' . $field_name . '<br>
Alter: ' . $field_age . '<br>
Geschlecht: ' . $field_ges . '<br>
Gamertag: ' . $field_gt . '<br>
SocialClub-Name: ' . $field_sona . '<br>
Rolle: ' . $field_rol;

$subject = 'xRL Anmeldung - ' . $field_rol . ': ' . $field_name;
$body_message = '<!DOCTYPE html>
<html>
<head>
<style>

html, body {
    margin: 0;
    padding: 0;
}

#Mailnap {
    text-align: center;
}

#Mailna {
    text-align: center;
}

.Hgrund {
    margin: 0;
    padding: 0;
    background-color: #DCDCDC;
}

table {
    height: 60px;
    width: 100%;
    border: 0px;
}

.Header {
    height: 60px;
    width: 100%;
    background-color: #1F1F1F;
    border: 0px;
}

.Header th {
    width: 83px;
    height: 60px;
    border: 0px;
    background-color: #DCDCDC;
}

.Header td {
    border: 0px;
    text-align: center;
}

.Header td a {
    fonz-size: 24px;
    text-align: center;
    color: #FFFFFF;
    border-bottom: 3px solid #FFFFFF;
    border-bottom-right-radius: 3px;
    border-bottom-left-radius: 3px;
    text-decoration: none;
}

.Header td a:hover {
    border-bottom: 3px solid #FF0000;
}

.Content {
    width: 98%;
    background-color: #696969;
    margin: 0 1% 0 1%;
    padding: 0;
}

.ContentICBG {
    width: 95%;
    padding: 0;
    margin: 10px auto 10px auto;
    background-color: #DCDCDC;
}

.Content h1 {
    width: 100%;
    margin: 0;
    padding: 0;
    font-size: 24px;
    text-align: center;
    background-color: #D5C4A1;
    color: #000000;
}

.ContentICBG p {
    padding: 10px 10px 10px 10px;
}
</style>
</head>
<body>
<p id="Mailnap"><a href="https://xGamesHub.com/DE/MailFeedback" id="Mailna">Wird diese Mail nicht richtig angezeigt? Klicke bitte hier, und lasse es und wissen!</a></p>

<div class="Hgrund">
<table style="background-color:#DCDCDC;border-bottom:3px solid #DCDCDC;">
 <tr class="Header">
  <th><img src="https://xForigens.com/de-DE/Clans/GTAxRL/xRLN60.png"/></th>
  <td><a href="https://xGamesHub.com/DE/" style="">STARTSEITE</a></td>
  <td><a href="https://xGamesHub.com/DE/Gaming-News/" style="">GAMING NEWS</a></td>
  <td><a href="https://xGamesHub.com/Forum" style="">Forum</a></td>
  <td><a href="https://xForigens.com/de-DE/Clans/SEK1" style="">SEK1</a></td>
  <td><a href="https://xForigens.com/de-DE/Clans/GTAxRL/" style="">xRL</a></td>
 </tr>
</table>

<div class="Content">
 <h1>' . $subject . '</h1>
 <div class="ContentICBG">
  <p>' . $overall_message . '</p>
 </div>
  <h1>Gesendet von: ' . $field_name . '</h1>
</div>

<div style="margin:0;padding:0;background-color:#1F1F1F;border-top:3px solid #DCDCDC;height:30px;width:100%">
 <p style="color:#FFFFFF;text-align:right;font-size:15px;margin:10px 10px 0 0;padding:0;"><a style="color:#FFFFFF;text-decoration:none;" href="https://xForigens.com/de-DE/About">Über</a> | &copy;2017 xForigens</p>
</div>
</div>
</body>
</html>'; 

$mail_to = 'Admin@xForigens.com';
$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
  <script language="javascript" type="text/javascript">
  alert('Danke, wir werden uns in den nächsten 7 Tagen melden.\n\nDamit Du mit am Projekt teilnehmen kannst, musst Du nun mit deinem angegebenen Gamertag, und deinem SocialClub-Name anfragen an Crew & Club senden!')
  window.history.back()
  </script>
<?php
}

else { ?>
  <script language="javascript" type="text/javascript">
  alert('Wenn die Mailfunktion ausfällt, versuche diese erneut zu senden, oder wende Dich an die Administration.')
  window.history.back();
  </script>
<?php
}

?>

在 Outlook.com 中,它不再显示任何内容,ÄÖÜ/äöü 之类的重音符号(或其他任何内容)不再正确显示,并且不同的邮件服务现在询问我是否希望我的标题图片是显示。之前它没有被问到。请帮忙。

【问题讨论】:

    标签: php html css email outlook


    【解决方案1】:

    您的第一个标题是:

    $headers .= "Content-Type: text/html; charset=UTF-8>\n";
    

    忽略其中的流氓>,您指定的是UTF-8。

    UTF-8 不支持变音符号等,您需要对所有特殊字符进行编码。

    【讨论】:

    • 我没有注意到 ">" 哈哈。删除后,元音变音,例如页脚链接“Über”现在再次正确显示。我不认为我也会支持变音符号,但有人告诉我不同​​。删除 > 后,它就可以正常工作了。谢谢
    猜你喜欢
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 1970-01-01
    • 2013-11-07
    • 1970-01-01
    • 2022-01-19
    相关资源
    最近更新 更多