2011-07-27 15 views
5

Possible Duplicate:
php mail() function on localhostヘルプPHPメール()関数

私は自分のサイト上でパスワード回復のためのいくつかのlocalhostのテストをやろうとしているが、私は電子メールを送信しようとすると、私は次のエラーを取得する:

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() 

私の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] 

localhostのテストでこれらを設定する方法がわかりません。 SMTPを私のプロバイダのメールサーバに設定する必要があることを認識していますが、私は共有オフィスビルで働いていますので、インターネットを誰が提供しているのかを知る方法もわかりません。

ありがとうございます。

答えて

2

PHPのメールにはローカルメールサーバーが必要です。

編集:mail()のPHPドキュメントサイトでは、PEARのメールパッケージを使用してください。

+0

...またはあなたがISPのものを使用することができますが1、簡単に同じマシン上にインストールされた電子メールサーバーなしで、任意のプラットフォームからメールを送信できるようにこれらのPHPライブラリは、実際にSMTPプロトコルを実装します。 – Shef

7

PHPのメール()関数は、直接SMTPプロトコルを実装していません。代わりにsendmail()MTA(SMTPサーバ)、またはpostfixやmstmpのような置換えに依存します。 MTAがインストールされている限り、Unix上で正常に動作します。

Windows上で(PHP.netから手動):だから

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).

- この話の教訓 - あなたは、メールサーバをインストールする必要があります。

しかし - だけではテスト目的のためだ場合 - 単に、実際にSMTPプロトコルを実装するPHPライブラリを取得し、電子メールを送信するために、あなたの通常のGmailのメールアドレスを使用します。

の代わりにPHPのメールを使用しては()これらのいずれかを使用します。

  1. phpmailerの
  2. ではSwiftMailer
  3. のZend \メール

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");