MailクラスでSMTPサーバを指定してメール送信を行うには、factory関数の第一引数に'smtp' 第二引数にSMTPサーバの設定を渡します。
Key | デフォルト | 内容 |
---|---|---|
host | localhost | SMTPサーバのアドレス |
port | 25 | ポート |
auth | false | SMTP認証の使用の有無 |
username | '' | SMTP認証のユーザー名 |
password | '' | SMTP認証のパスワード |
後は、'mail'を指定した場合と変わりません。
<?php require_once "Mail.php"; $params = array( 'host' => 'mail.example.org', 'port' => '25', 'auth' => false, 'username' => '', 'password' => '', ); $recipients = 'bnote@example.com'; $headers['From'] = 'root@example.com'; $headers['To'] = 'bnote@example.com'; $headers['Subject'] = 'My Subject'; $body = "Message\nMessage\nMessage\n"; $objMail =& Mail::factory('smtp', $params); $result = $objMail->send($recipients, $headers, $body); if (PEAR::isError($result)) { die($result->getMessage()); } ?>
Copyright 1997-2010 BBB All rights reserved.