2017-01-04 46 views
2

http://webprojects.co/dev_wed/mail.php試圖使用該腳本從服務器發送郵件,但我沒有能夠從服務器發送郵件無法使用PHP的mail發送郵件()函數

<?php 
 
$to = "[email protected]"; 
 
$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> 
 
"; 
 

 

 
$headers = "MIME-Version: 1.0" . "\r\n"; 
 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
 
$headers .= 'From: <[email protected]>' . "\r\n"; 
 
$headers .= 'Cc: [email protected]' . "\r\n"; 
 

 
$result = mail($to,$subject,$message,$headers); 
 

 
if(!$result) { 
 
    echo "Error"; 
 
} else { 
 
    echo "Success"; 
 
} 
 
?>
始終顯示錯誤嘗試發送使用PHP郵件()函數的電子郵件

+0

你有沒有試過尋找更多的細節,如「錯誤」的確切原因? – emaillenin

+0

我已經嘗試過但沒有得出任何結論。你可以提出任何方法來找到確切的問題@emaillenin –

回答

1

您是在線測試代碼還是通過本地主機? mail()函數在沒有SMTP的localhost中不起作用。

+0

我知道郵件()不能在本地主機上工作。在http://webprojects.co/dev_wed/mail.php在線測試我的代碼 –

+0

我在dhjcastelijns.nl/index.php上運行完全相同的代碼並取得成功。也許它與你的網絡服務器有關?我在Raspberry Pi上曾遇到過這個問題,因爲沒有安裝郵件服務器。 –

+0

所以我的代碼沒有問題我想我在這裏面臨同樣的問題你能幫我嗎我怎樣才能安裝郵件更嚴格? –

相關問題