2015-05-19 101 views
0

我正在開發一個Web應用程序,並且在某些時候我需要發送確認郵件。 Sendmail在安裝,但是當我嘗試運行這個代碼時,它加載頁面非常慢,沒有任何反應。在Ubuntu上無法使用Php mail()14.04

<?php 
$to = "[email protected]"; 
$subject = "Confimation"; 

$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: <[email protected]>' . "\r\n"; 

mail($to,$subject,$message,$headers); 
?> 

這是mail.log

May 19 13:18:02 al-Inspiron-5548 sendmail[6934]: t4JBI24R006934: from=www-data, size=416, class=0, nrcpts=0, msgid=<[email protected]>, [email protected] 
May 19 13:18:02 al-Inspiron-5548 sendmail[6936]: t4JBI2ex006936: from=www-data, size=416, class=0, nrcpts=0, msgid=<[email protected]>, [email protected] 

有人能幫助我嗎?

+0

這是一臺本地計算機嗎?我想是因爲電腦的名字。大多不可能從家庭網絡發送電子郵件。 – Richard

+0

如果您的sendmail設置有效,並且您的防火牆允許端口25出站,那麼幾乎可以肯定的是您的問題在於gmail將此電子郵件視爲垃圾郵件 –

+0

查看您的中繼,您的郵件服務器在本地安裝,與公衆無關在端口25上的IP,您需要使用公共IP從您的計算機發送郵件。 –

回答

0

要發送任何郵件到另一臺服務器,您應該有自己的郵件服務器的詳細信息。

在這裏,您嘗試使用localhost向GMAIL發送電子郵件,這是不可能的。您應該設置您的服務器或您的發件人電子郵件(Gmail,雅虎等)的SMTP自己的詳細信息。

PHP有一些很酷的庫可以幫助你,比如PHPMailer

已經有帖子可以幫助你。 Sending email with PHP from SMTP SERVER

一切都好!

+0

實際上可以從本地主機發送。但它需要sendmail配置,而不是php配置。如果將sendmail配置爲始終將gmail用作智能主機,則使用提交端口和經過驗證的(加密的)連接,則純php mail()命令將正常工作。但是,使用PHPMailer之類的東西可能更容易。 –

+0

是的,您可以通過在php.ini下設置詳細信息來完成。這篇文章會爲你提供幫助。 http://stackoverflow.com/questions/112190/php-ini-smtp-how-do-you-pass-username-password –

+0

我通過上面的配置發送的一些郵件到達我的gmail標記爲垃圾郵件,但它至少需要一個小時才能發送和接收郵件 – user3712139