在php echo页面上添加favicon


Add favicon on php echo page

我刚刚在HTML网站上创建了一个简单的php表单。一切都很好,但我想在回声页面上添加一个收藏夹。。。我实际上使用的是这个代码:

    <?php $name = $_POST['demo-name'];
    $email = $_POST['demo-email'];
    $message = $_POST['demo-message'];
    $formcontent="From: $name 'n Email: $email 'n Message: $message";
    $recipient = "myemail@gmx.net";
    $subject = "Message from ...";
    $mailheader = "From: $email 'r'n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    echo "<body style='background-color:#000000; color:#ffffff; font-family:arial; font-size:20px; padding-top: 100px' align='center' >" . " " . "Thank You! </br> </br><a href='index.html' style='text-decoration:none; color:#f3bd46;'> Return to ...</a></body>";
    ?>

您应该将HTML代码包含在您最喜欢的图标中:

<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">

我相信"echo-page"指的是表单提交后的php页面,该页面由您共享的代码组成
该页面不需要全部是php代码,所以您可以在php邮件代码下面做纯html,而不是回显html
所以php文件看起来是这样的,favicon在html头中。

<?php
    $name = $_POST['demo-name'];
    $email = $_POST['demo-email'];
    $message = $_POST['demo-message'];
    $formcontent="From: $name 'n Email: $email 'n Message: $message";
    $recipient = "myemail@gmx.net";
    $subject = "Message from ...";
    $mailheader = "From: $email 'r'n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
  <link rel="shortcut icon" href="favicon.ico">
  <style>
   body{
    background-color:#000;
    color:#fff;
    font-family:arial;
    font-size:20px;
    padding-top: 100px;
    text-align:center;
   }
   a{
    text-decoration:none;
    color:#f3bd46;
   }
  </style>
</head>
<body>
    Thank You! <br/><br/>
    <a href='index.html'> Return to ...</a>
</body>
</html>

尽管您已经有了一个有效的答案,但为了让事情更清楚,您可以尝试删除eco部分,并用以下示例替换它:

<?php
$output  = '<!DOCTYPE HTML>';
$output .= '<html><head><title></title>';
$output .= '<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">';
$output .= '<link rel="icon" href="/favicon.ico" type="image/x-icon">';
$output .= '</head>';
$output .= '<body style="background-color:#000000; color:#ffffff; font-family:arial; font-size:20px; padding-top: 100px" align="center">';
$output .= 'Thank You! </br></br><a href="index.html" style="text-decoration:none; color:#f3bd46;"> Return to ...</a></body>';
$output .= '</html>';
echo $output;
?>

请注意,如果源代码的外观对您很重要,您可能需要对代码进行一些调整,如添加新行和制表符,以及在需要时更改和转义引号。

如今,这不仅仅是创建几个标签和添加一个favicon.ico文件。您应该在此处使用Favicon Generator等工具:http://realfavicongenerator.net/

它为Android、iOS、MacOS、Windows Phone等生成并预览您的收藏夹图标。