2011-07-27 10 views
5

Possible Duplicate:
php mail() function on localhostPomoc z poczty() w PHP funkcji

Próbuję zrobić kilka testów localhost do odzyskiwania hasła na moim miejscu, ale gdy próbuję wysłać wiadomość e-mail, pojawia się następujący błąd:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() 

Oto odpowiednie ustawienia w moim pliku php.ini.

; For Win32 only. 
; http://php.net/smtp 
SMTP = localhost 
; http://php.net/smtp-port 
smtp_port = 25 

; For Win32 only. 
; http://php.net/sendmail-from 
sendmail_from = [email protected] 

Nie jestem pewien, co ustawić te do testowania localhost. Zdaję sobie sprawę, że muszę ustawić SMTP na jakimkolwiek serwerze pocztowym mojego dostawcy, ale pracuję w wspólnym budynku biurowym, więc nie wiem, jak się dowiedzieć, kto tu zapewnia internet.

Z góry dziękuję.

Odpowiedz

2

Poczta PHP wymaga lokalnego serwera poczty do uruchomienia.

Edycja: Jak podaje się strona dokumentacji PHP dla mail(), możesz użyć pakietu Mail od PEAR.

+0

... czy można użyć jednego ISP. – Shef

7

poczty PHP() nie implementuje protokół SMTP bezpośrednio. Zamiast tego bazuje na sendmail() MTA (serwer SMTP) lub na zastępstwie takim jak postfix lub mstmp. Działa na Unix tak długo, jak długo zainstalowany jest MTA.

W Windows (od php.net manual):

The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

Więc - morał z tej historii - trzeba zainstalować serwer poczty.

Jednak - czy to dla celów testu tylko - po prostu dostać biblioteki PHP, które faktycznie implementuje protokół SMTP i użyć zwykłego adresu e-mail Gmail do wysyłania e-maili:

Zamiast poczty PHP() użyć jednego z nich:

  1. PHPMailer
  2. SwiftMailer
  3. Zend \ Poczta

tych bibliotek PHP faktycznie wdrożenia protokołu SMTP tak łatwo można wysyłać e-maile z dowolnej platformy, bez zainstalowanego na tym samym komputerze serwera e-mail: przykład

PHPMailer:

$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "stmp.gmail.com"; // SMTP server 
$mail->SMTPDebug = 1;      // enables SMTP debug information (for testing) 
// 1 = errors and messages 
// 2 = messages only 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->SMTPSecure = "ssl";     // sets the prefix to the servier 
$mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
$mail->Port  = 465;     // set the SMTP port for the GMAIL server 
$mail->Username = "[email protected]"; // GMAIL username 
$mail->Password = "pass111";   // GMAIL password 
$mail->SetFrom('[email protected]', 'My name is slim shady'); 
$mail->AddReplyTo("[email protected]","My name is slim shady"); 
$mail->Subject = "Hey, check out http://www.site.com"; 
$mail->AltBody = "Hey, check out this new post on www.site.com"; // optional, comment out and test 
$mail->MsgHTML($body); 
$address = "[email protected]"; 
$mail->AddAddress($address, "My name is slim shady");