2014-10-28 61 views
0

我在php.ini文件中設置了SMTP和smtp_port。它已經在那裏了。在服務器上發送電子郵件

ini_set("SMTP","ssl://smtp.gmail.com"); 
ini_set("smtp_port","465"); 

現在,我想這個發送電子郵件:

$to  = '[email protected]'; 
$subject = 'the subject'; 
$message = 'hello'; 
$headers = 'From: [email protected]' . "\r\n" . 
     'Reply-To: [email protected]' . "\r\n" . 
     'X-Mailer: PHP/' . phpversion(); 

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

錯誤:

Message: mail(): Failed to connect to mailserver at 
       "ssl://smtp.gmail.com" port 465, verify your "SMTP" and 
       "smtp_port" setting in php.ini or use ini_set() 

是這一點,因爲認證問題?我不想用PHPMailer

+0

您可能會在這裏找到一些幫助:http://stackoverflow.com/questions/16048347/send -email-使用Gmail郵箱的SMTP服務器,通過-PHP-郵件。 – 2014-10-28 16:21:43

+0

謝謝@Zeratops。但是,我想在PHP中使用默認的電子郵件功能。不是'PHPMailer' – 2014-10-28 16:23:27

回答

0

您必須提供自己的Gmail crendentials(登錄名和密碼),通過谷歌的SMTP服務器發送郵件
的PHP mail()功能不提供此功能
我建議你下載並使用這個PHP項目:https://github.com/Synchro/PHPMailer 隨着它可以做的一切:Gmail的憑據,附加文件,用HTML寫郵件....
希望可以幫助:)

+1

這是一個非官方的分支,最好使用官方的https://github.com/PHPMailer/PHPMailer – rjdown 2014-10-28 16:46:05

相關問題