PHP mail() 函数与 html 不起作用


PHP mail() function with html not working

我在mail()上遇到了问题。我试图制作 html 电子邮件发送,但随后我的网站无法正常工作。

代码:

    $tresc = '<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css" media="screen">
        .ExternalClass * {line-height: 100%}
        /* Début style responsive (via media queries) */
        @media only screen and (max-width: 480px) {
            *[id=email-penrose-conteneur] {width: 100% !important;}
            table[class=resp-full-table] {width: 100%!important; clear: both;}
            td[class=resp-full-td] {width: 100%!important; clear: both;}
            img[class="email-penrose-img-header"] {width:100% !important; max-width: 340px !important;}
        }
        /* Fin style responsive */
    </style>
</head>
<body style="background-color:#30606b">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css" media="screen">
        .ExternalClass * {line-height: 100%}
        /* Début style responsive (via media queries) */
        @media only screen and (max-width: 480px) {
            *[id=email-penrose-conteneur] {width: 100% !important;}
            table[class=resp-full-table] {width: 100%!important; clear: both;}
            td[class=resp-full-td] {width: 100%!important; clear: both;}
            img[class="email-penrose-img-header"] {width:100% !important; max-width: 340px !important;}
        }
        /* Fin style responsive */
    </style>
<div align="center" style="background-color:#30606b;">
        <!-- Début en-tête -->
    <table id="email-penrose-conteneur" width="660" align="center" style="padding:20px 0px;" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
                <table width="660" class="resp-full-table" align="center" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="50%" style="text-align:center;">
                            <a href="https://ss.pl"><img src="http://i.imgur.com/OGoCClJ.png" alt="Logo" border="0"></a>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
        <!-- Fin en-tête -->
    <table id="email-penrose-conteneur" width="660" align="center" style="border-right:1px solid #e2e8ea; border-top:1px solid #e2e8ea; border-bottom:1px solid #e2e8ea; border-left:1px solid #e2e8ea; background-color:#ffffff;" border="0" cellspacing="0" cellpadding="0">
        <!-- Début bloc "mise en avant" -->
        <tr>
            <td style="background-color:#6d8f97">
                <table width="660" class="resp-full-table" align="center" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="resp-full-td" valign="top" style="padding:20px; text-align:left;">
                            <span style="font-size:30px; font-family:'Helvetica Neue', helvetica, arial, sans-serif; font-weight:100; color:#ffffff"><a href="" style="color:#ffffff; outline:none; text-decoration:none;">Drogi użytkowniku!</a></span></p>
                            <span style="font-size:16px; font-family:'Helvetica Neue', helvetica, arial, sans-serif; color:#fff"><p align="left">Dziękujemy za rejestrację w serwisie ddd.pl!<br>Nasz serwis to wspaniała szansa na zdobycie wymarzonych nagród.<br><br>
                            Aby rozpocząć zabawę na naszym portalu musisz aktywować konto.<br>
                        Kliknij na przycisk '<b>Aktywuj Konto</b>' poniżej.</span>
                        </td>
                    </tr>
                    <tr>
                        <td width="100%" class="resp-full-td" valign="top" style="padding: 0px 20px 20px 20px;">
                            <table align="center" border="0" cellspacing="0" cellpadding="0" style="margin:auto; padding:auto;">
                                <tr>
                                    <td style="background-color:#ffffff; border-radius:3px; padding: 10px 40px;">
                                        <a style="font-family:'Helvetica Neue', helvetica, arial, sans-serif; text-align: center; text-decoration: none; display:block; color:#6d8f97; font-weight : 200; font-size: 25px;" href="#">Aktywuj konto</a>
                                    </td>
                                </tr>
                            </table><span style="font-size:16px; font-family:'Helvetica Neue', helvetica, arial, sans-serif; color:#fff"><p align="left">W razie problemów, kliknij na bezpośredni link:
                <br><br>
Oto Twoje dane do logowania:<br><br>
<b>Login:</b><br>
<b>Hasło:</b><br><hr>               
                    </td>
                    </tr>
                    <tr>
                        <td width="100%" valign="top">
                            <table align="center" border="0" cellspacing="0" cellpadding="0" style="margin:auto; padding:auto;">
                                <tr>
                                    <td style="text-align:center; padding:0px 20px;">
                                        <img src="http://i.imgur.com/F9NiOff.png" class="email-penrose-img-header" alt="prezent_grafika" border="0" style="display:block">
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <!-- Fin bloc "mise en avant" -->
        <!-- Début article 1 -->
        <tr>
            <td style="border-bottom: 1px solid #e2e8ea">
                <table width="660" class="resp-full-table" align="center" border="0" cellspacing="0" cellpadding="0" style="padding:20px;">
                    <tr>
                        <td width="100%">
                            <table width="120" align="left" class="resp-full-table" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="100%" class="resp-full-td" style="text-align: center;"><img src="http://i.imgur.com/a2nyPke.jpg" width="120px" style="border-radius:3px;" alt="kubek_obrazek" border="0">
                                    </td>
                                </tr>
                            </table>
                            <table width="1" align="left" class="resp-full-table" border="0" cellpadding="0" cellspacing="0" >
                                <tr>
                                    <td width="100%" height="20"></td>
                                </tr>
                            </table>
                            <table width="480" align="right" class="resp-full-table" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="100%" class="resp-full-td" valign="top" style="text-align : justify;">
                                        <a href="#" style="outline:none; text-decoration:none"><span style="font-size:25px; font-weight: bold; font-family:'Helvetica Neue', helvetica, arial, sans-serif; color:#313131;">Zgarnij kubek</span></a><br />
                                        <hr align="left" style="width:100px; margin-left:0px; text-align:left; background-color:#2ecc71; color:#2ecc71; height: 2px; border: 0 none;" />
                                        <span style="font-size:16px; font-family:'Helvetica Neue', helvetica, arial, sans-serif; color:#313131">Aktualnie trwa akcja pod nazwą "Kubek z poleconych". Zbierz 20 poleconych i odbierz swoją pierwszą nagrodę w naszym serwisie - kubek! Więcej informacji znajdziesz klikając w przycisk poniżej.</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td width="100%" class="resp-full-td" valign="top" style="padding-top:20px;">
                                        <table align="right" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td style="background-color:#2ecc71; border-radius:3px; padding: 6px 24px;">
                                                    <a style="font-family:'helvetica neue', helvetica, arial, sans-serif; color:#ffffff; text-align: center; text-decoration: none; display:block; font-weight : 200; font-size: 16px;" href="#">Więcej o kubku</a>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <!-- Fin article 1 -->
        <!-- Début article 2 -->
        <tr>
            <td style="border-bottom: 1px solid #e2e8ea">
                <table width="660" class="resp-full-table" align="center" border="0" cellspacing="0" cellpadding="0" style="padding:20px;">
                    <tr>
                        <td width="100%">
                            <table width="120" align="left" class="resp-full-table" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="100%" class="resp-full-td" style="text-align: center;"><img src="http://i.imgur.com/6iBiIV1.jpg" width="120px" style="border-radius:3px;" alt="Image article 2" border="0">
                                    </td>
                                </tr>
                            </table>
                            <table width="1" align="left" class="resp-full-table" border="0" cellpadding="0" cellspacing="0" >
                                <tr>
                                    <td width="100%" height="20"></td>
                                </tr>
                            </table>
                            <table width="480" align="right" class="resp-full-table" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="100%" class="resp-full-td" valign="top" style="text-align : justify;">
                                        <a href="#" style="outline:none; text-decoration:none"><span style="font-size:25px; font-weight: bold; font-family:'Helvetica Neue', helvetica, arial, sans-serif; color:#313131;">Oficjalny konkurs</span></a><br />
                                        <hr align="left" style="width:100px; margin-left:0px; text-align:left; background-color:#2ecc71; color:#2ecc71; height: 2px; border: 0 none;" />
                                        <span style="font-size:16px; font-family:'Helvetica Neue', helvetica, arial, sans-serif; color:#313131">Na naszej stronie trwa konkurs, w którym do wygrania są punkty, długopis, a nawet pendrive 16GB! Wystarczy, że zrobisz zdjęcie... Więcej informacji uzyskasz klikając w przycisk poniżej.</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td width="100%" class="resp-full-td" valign="top" style="padding-top:20px;">
                                        <table align="right" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td style="background-color:#2ecc71; border-radius:3px; padding: 6px 24px;">
                                                    <a style="font-family:'helvetica neue', helvetica, arial, sans-serif; color:#ffffff; text-align: center; text-decoration: none; display:block; font-weight : 200; font-size: 16px;" href="#">Więcej o konkursie</a>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <!-- Fin article 2 -->
        <!-- Début article 3 -->
        <tr>
            <td style="border-bottom: 1px solid #e2e8ea">
                <table width="660" class="resp-full-table" align="center" border="0" cellspacing="0" cellpadding="0" style="padding:20px;">
                    <tr>
                        <td width="100%">
                            <table width="120" align="left" class="resp-full-table" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="100%" class="resp-full-td" style="text-align: center;"><img src="http://i.imgur.com/m9yrVxg.jpg" width="120px" style="border-radius:3px;" alt="fanpage_obrazek" border="0">
                                    </td>
                                </tr>
                            </table>
                            <table width="1" align="left" class="resp-full-table" border="0" cellpadding="0" cellspacing="0" >
                                <tr>
                                    <td width="100%" height="20"></td>
                                </tr>
                            </table>
                            <table width="480" align="right" class="resp-full-table" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="100%" class="resp-full-td" valign="top" style="text-align : justify;">
                                        <a href="#" style="outline:none; text-decoration:none"><span style="font-size:25px; font-weight: bold; font-family:'Helvetica Neue', helvetica, arial, sans-serif; color:#313131;">Oficjalny Fanpage</span></a><br />
                                        <hr align="left" style="width:100px; margin-left:0px; text-align:left; background-color:#2ecc71; color:#2ecc71; height: 2px; border: 0 none;" />
                                        <span style="font-size:16px; font-family:'Helvetica Neue', helvetica, arial, sans-serif; color:#313131">Jak większość firm, tak i my posiadamy swoja stronę na Facebooku. Polub ją by być na bieżąco. Dodatkowo, na fanpage'u pojawią się konkursy z nagrodami - nie przegap tej szansy!</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td width="100%" class="resp-full-td" valign="top" style="padding-top:20px;">
                                        <table align="right" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td style="background-color:#2ecc71; border-radius:3px; padding: 6px 24px;">
                                                    <a style="font-family:'helvetica neue', helvetica, arial, sans-serif; color:#ffffff; text-align: center; text-decoration: none; display:block; font-weight : 200; font-size: 16px;" href="#">Polub nasz Fanpage</a>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <!-- Fin article 3 -->

    <table id="email-penrose-conteneur" width="600" align="center" style="padding:20px 0px;" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
                <table width="600" class="resp-full-table" align="center" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="100%" class="resp-full-td" style="text-align: center;"><span style="font-size:12px; font-family:'Helvetica Neue', helvetica, arial, sans-serif; color:#aeb2b3">Otrzymałeś tę wiadomość, ponieważ założyłeś konto na .pl.<br>Nasz serwis wymaga aktywacji konta.<br>Jeśli nie chcesz otrzymywać wiadomości oraz usunąć konto napisz: admin@pl.</span>
                        <hr align="left" style="margin-left:0px; text-align:left; background-color:#aeb2b3; color:#aeb2b3; height: 1px; border: 0 none;" />
                        <span style="font-size:12px; font-family:'Helvetica Neue', helvetica, arial, sans-serif; color:#aeb2b3">Design by Penrose & edited by .pl</span>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <!-- Fin footer -->
</div>
</body>
';


                mail($tomail,$topic,$tresc."'n'n'n".$stopka, "From: $admin_mail'r'n"
        ."Reply-To: $from'r'nMIME-Version: 1.0'r'n"."Content-type: text/html; charset=iso-8859-2'r'n ");

请帮助我!当我得到这个时,网站无法正常工作(内部 500)。我做错了什么?"tresc"一词的意思是"文本"

Kliknij na przycisk '<b>Aktywuj Konto</b>' poniżej.</span>中,您失去了字符串连续性'您应该改用''。您应该替换消息正文中'的所有出现''

试试这个方式。我已经解决了此代码的问题。来源于w3schools

<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "'r'n";
$headers .= "Content-type:text/html;charset=UTF-8" . "'r'n";
// More headers
$headers .= 'From: <webmaster@example.com>' . "'r'n";
$headers .= 'Cc: myboss@example.com' . "'r'n";
mail($to,$subject,$message,$headers);
?>