代码之家  ›  专栏  ›  技术社区  ›  Nrc

使用php mail设置邮件地址样式

  •  0
  • Nrc  · 技术社区  · 6 年前

    <?php
    
    $to = htmlspecialchars("info@example.com");
    $subject = htmlspecialchars("Subject");
    
    $message = "
    <html>
    <head>
    <title>HTML email</title>
    </head>
    <body>
    
    <table>
    
    <tr>
        <td style='outline:0; text-decoration: none;'>
        info@example.com</td>
    </tr>
    </table>
    
    </body>
    </html>
    ";
    
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= 'From: <info@example2.com>' . "\r\n";
    
    mail($to, $subject, $message, $headers);    
    
    ?>
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   vieroli    6 年前

    可以在中添加标记。只需像普通的html页面一样工作。 在以前的项目中尝试过,效果很好。

    <?php
    
    $to = htmlspecialchars("info@example.com");
    $subject = htmlspecialchars("Subject");
    
    $message = "
    <html>
    <head>
    
    <style>
    td{outline:0; text-decoration: none;}
    p{font-weight:bold;color:red;}
    a{text-decoration: none; border: 0; color: red; font-weight:bold;}
    </style>
    
    <title>HTML email</title>
    </head>
    <body>
    
    <table>
    
    <tr>
        <td><a href="mailto:info@example.com">info@example.com</a></td>
    </tr>
    </table>
    <p>My paragraph has style !</p>
    </body>
    </html>
    ";
    
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= 'From: <info@example2.com>' . "\r\n";
    
    mail($to, $subject, $message, $headers);    
    
    ?>
    
        2
  •  1
  •   Nikita Leshchev    6 年前

    包装电子邮件地址

    <a href="mailto:info@example.com">info@example.com</a>