[英]How to send a mail from PHP using gmail?
我是PHP的初學者,但我想將郵件發送到@ yahoo.com,@ gmail.com和其他類似的電子郵件地址。 我已經閱讀了一些教程,但是我沒有SMTP服務器(我什至不知道那是什么),但是我已經閱讀過可以通過GMail(smtp.gmail.com)發送的地方。 這怎么可能 ?
我正在Windows 7上運行Apache服務器。
我已經在Windows 7環境中結合了Google帳戶實現了msmtp.sourceforge.net ,就像夢一樣。
The configuration file you'll need for Gmail is as follows:
A system wide configuration is optional.
# If it exists, it usually defines a default account.
# This allows msmtp to be used like /usr/sbin/sendmail.
account default
# The SMTP smarthost.
host smtp.gmail.com
domain smtp.gmail.com
tls on
tls_certcheck off
tls_starttls on
auth on
user user@domain.co.uk
from user@domain.co.uk
password yourpasswordhere
port 587
logfile C:\msmtp\msmtplog.txt
# Construct envelope-from addresses of the form "user@oursite.example".
auto_from on
maildomain user@domain.co.uk
其他信息可在msmtp提供的文檔中找到,但實質上與下載的文件,此配置以及對php.ini文件的略微調整有關,您應該可以使用。
使用phpmailer類,這里是下載phpmailer類的示例代碼goto http://sourceforge.net/projects/phpmailer/
require('./class.phpmailer/class.phpmailer.php');
if(isset($_GET['name'])&&isset($_GET['email'])&&isset($_GET['message']))
{
define('GUSER', 'youremail@gmail.com'); // GMail username
define('GPWD', 'yourgmailpass'); // GMail password
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.googlemail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) { echo 'error';}
else{echo 'message send';}
}
$name="sender : ".$_GET['email']."";
$message=$name."\n".$_GET['message'];
$subject="a Message from :".$_GET['name'];
smtpmailer('Destinationemail@yahoo.com', '', 'youremail@mail.com',$subject ,$message , $message);
您可以使用PHPMailer做到這一點。 這是一個教程
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.