php
  • email
  • 2015-08-25 54 views -1 likes 
    -1

    我無法發送郵件的HTML格式PHP的mail()不能查看HTML

    $to=$email; 
        $obj='verify mail firstdj.eu'; 
        $message="<html><head><title>Email confirm</title></head><body><table style='width: 100%;max-width: 600px;margin-left: 50%;transform: translateX(-50%);'><tr><th style='text-align: -webkit-center !important;text-align: -moz-center !important;text-align:center;'><div style='position: relative;box-shadow: black 0px 2px 3px;letter-spacing: 1px;width: 100%;max-width: 550px;height:180px;background-color:#3B2C6C;color:white;border: 1px solid #8F8787;    '><img src='./img/logoEmail.png'><img src='./sito/party.png' style='width: 100%;height: 50px;position:absolute; bottom:0px;left:0px;'></div></th></tr><tr><td style='text-align: -webkit-center !important;text-align: -moz-center !important;text-align:center;'><div style='width: 100%;    max-width: 550px;border: 5px solid #3B2C6C;box-sizing: border-box;text-align:left'><div style='padding:7px;font-family: arial,sans-serif;font-size: 15px;'>hi marco,<br><br>thanks for choosing us    now,<br>to complete your signing up click <a href='verify_email.php?name=marco'>here</a></div></div></td></tr></table></body></html>"; 
        $header='From: Thorny_firstdj.eu<[email protected]>'.'\r\n'; 
        $header .= 'MIME-Version: 1.0'.'\r\n'; 
        $header .='Content-Type: text/html; charset=ISO-8859-1'.'\r\n';  
        $emailCon=mail($to,$obj,$message,$header); 
    

    我住進了php.ini中的mail.add_x_header爲ON。 我在哪裏做錯了?

    +2

    這是你的報價在標題,最有可能的。那些不會被單引號解析。 RTM http://php.net/manual/en/function.mail.php',「\ r \ n」);' –

    +0

    也許是因爲行不應該大於70個字符? – thorny84

    +0

    我懷疑這一點。如果有的話,你會得到部分消息。 –

    回答

    2

    根據您的編輯,您並未將\r\n的單引號更改爲雙引號。

    按手冊:http://php.net/manual/en/function.mail.php

    // To send HTML mail, the Content-type header must be set 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    
    // Additional headers 
    $headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; 
    $headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; 
    $headers .= 'Cc: [email protected]' . "\r\n"; 
    $headers .= 'Bcc: [email protected]' . "\r\n"; 
    

    因此改變那些:

    $header = 'From: Thorny_firstdj.eu<[email protected]>' . "\r\n"; 
    $header .= 'MIME-Version: 1.0' . "\r\n"; 
    $header .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n"; 
    

    \r\n的沒有得到正確解析單引號中,如已經在註釋中規定。

    但是,在一些(罕見的)情況下,我看到From:需要低於最後一個聲明。

    你可以嘗試:

    $header = 'MIME-Version: 1.0' . "\r\n"; 
    $header .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n"; 
    $header .= 'From: Thorny_firstdj.eu<[email protected]>' . "\r\n"; 
    

    另一件事,這是不行的

    <a href='verify_email.php?name=marco'>here</a> 
    

    你應該用一個完整的HTTP調用:

    <a href='http://www.example.com/verify_email.php?name=marco'>here</a> 
    

    在沒有這樣做,該人將點擊他們的電腦將自己的電腦上的文件視爲什麼。

    正如評論所說,你最好使用這些

    改爲o f必須與mail()的標題作鬥爭。

    「我檢查了php.ini mail.add_x_header是否打開。」

    如果您對系統文件進行了任何更改,請確保Apache/PHP已重新啓動。

    如果您沒有這些更改,則不會發生,那就是如果您在本地機器上運行。

    error reporting添加到您的文件的頂部,這將有助於發現錯誤。

    <?php 
    error_reporting(E_ALL); 
    ini_set('display_errors', 1); 
    
    // rest of your code 
    

    旁註:顯示錯誤應該只在分期完成,並且從不生產。

    +0

    注意。現在我嘗試用phpmailer,我讀了它是非常好的 – thorny84

    +0

    @ thorny84 bizarro。這應該起作用。是的,swiftmailer一個phpmailer非常好。給我一分鐘,我會看看我是否沒有錯過任何東西。將測試它。 –

    +0

    @ thorny84我測試了這個,以HTML的形式出現。仔細檢查您的設置。如果您對系統文件進行了更改(如果在本地計算機上),請確保您重新啓動了所有服務。也使用錯誤報告。在打開PHP標記 (例如'<?php error_reporting(E_ALL);)後立即在文件頂部添加錯誤報告。 ini_set('display_errors',1);'然後你的代碼的其餘部分,看看它是否產生任何東西。儘管如此,你還是應該玩CSS,桌子的屏幕是25%。 –

    相關問題