質問
私の PHP Web アプリでは、特定のエラーが発生するたびに電子メールで通知を受け取りたいと考えています。これらを送信するために Gmail アカウントを使用したいと考えています。どうすればこんなことができるのでしょうか?
解決
Gmail の SMTP サーバーには、非常に特殊な構成が必要です。
から Gmail ヘルプ:
Outgoing Mail (SMTP) Server (requires TLS)
- smtp.gmail.com
- Use Authentication: Yes
- Use STARTTLS: Yes (some clients call this SSL)
- Port: 465 or 587
Account Name: your full email address (including @gmail.com)
Email Address: your email address (username@gmail.com)
Password: your Gmail password
これらの設定はおそらく次で行うことができます 梨::メール または PHPメーラー. 。詳細については、ドキュメントを参照してください。
他のヒント
PEARのメール機能をGmailのSMTPサーバーで利用可能
Gmail の SMTP サーバーを使用して電子メールを送信する場合、$from の値に関係なく、Gmail アドレスから送信されたように見えることに注意してください。
(以下のコードは About.com プログラミングのヒント )
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
// stick your GMAIL SMTP info here! ------------------------------
$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";
// --------------------------------------------------------------
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
所属していません StackOverflow