在我的PHP web应用程序中,每当出现某些错误时,我都希望通过电子邮件得到通知。我想用我的Gmail帐户发送这些邮件。这是怎么做到的?
使用Gmail的PHP邮件
原标题:
最佳回答
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
问题回答
你可以在Gmail的SMTP服务器上使用PEAR的邮件功能
请注意,当使用Gmail的SMTP服务器发送电子邮件时,它看起来就像来自你的Gmail地址,尽管你的价值是$from。
(以下代码取自About.com编程技巧)
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,
How 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>");
}
?>
相关问题
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding