function sendMail($message,$subject,$to,$clientName='') { include_once("class.phpmailer.php"); include_once("class.smtp.php"); //声明类,创建发送邮件的对象 $mail=new PHPMailer();
$mail->IsSMTP(); $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
没有可能啊..
还是你的问题是想用你的gmail账户来写php 发送邮件?
就是用户注册后,发一封用户信息到用户的邮箱里。我的邮箱是gmail的。也就是用我的gmail邮箱发一封信给用户的邮箱。我用126 ,qq邮箱测试都可以发送成功,唯独gmail的不行。由于服务器在美国,126,qq邮箱发送邮件延时太厉害了,才考虑用gmail.
{ include_once("class.phpmailer.php");
include_once("class.smtp.php");
//声明类,创建发送邮件的对象
$mail=new PHPMailer();
$mail->IsSMTP();
$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
$mail->Username = "xxx"; // GMAIL username
$mail->Password = "xxx"; // GMAIL password
$mail->CharSet = "utf-8"; // 这里指定字符集!如果是utf-8则将gb2312修改为utf-8
$mail->Encoding = "base64";
$mail->From = ""
$pieces = explode('@', $to);
$mail->FromName = '';
$mail->Subject = "=?UTF-8?B?" . base64_encode("$subject") . "?=";
$mail->Body = $message; //HTML Body
$mail->WordWrap = 50; // set word wrap
$mail->AddAddress($to,$pieces[0]);//邮件发送地址
$mail->AddReplyTo($to,$pieces[0]);//恢复地址
$mail->IsHTML(true); // send as HTML
if($mail->Send())
{
return ok;
}
1. <?php
2. include("class.phpmailer.php"); //匯入PHPMailer類別
3.
4. $mail= new PHPMailer(); //建立新物件
5. $mail->IsSMTP(); //設定使用SMTP方式寄信
6. $mail->SMTPAuth = true; //設定SMTP需要驗證
7. $mail->SMTPSecure = "ssl"; // Gmail 的SMTP主機需要使用SSL連線
8. $mail->Host = "smtp.gmail.com"; //Gamil的SMTP主機
9. $mail->Port = 465; //Gamil的SMTP主機的SMTP埠位為465埠。
10. $mail->CharSet = "big5"; //設定郵件編碼
11.
12. $mail->Username = "*********"; // 設定驗證帳號
13. $mail->Password = "*********"; // 設定驗證密碼
14.
15. $mail->From = [email protected]; //設定寄件者信箱
16. $mail->FromName = "測試人員"; //設定寄件者姓名
17.
18. $mail->Subject = "PHPMailer 測試信件"; //設定郵件標題
19. $mail->Body = "大家好,
20. 這是一封測試信件!
21. "; //設定郵件內容
22. $mail->IsHTML(true); //設定郵件內容為HTML
23. $mail->AddAddress("[email protected]", "茶米"); //設定收件者郵件及名稱
24.
25. if(!$mail->Send()) {
26. echo "Mailer Error: " . $mail->ErrorInfo;
27. } else {
28. echo "Message sent!";
29. }
30. ?>
http://bbs.shangmail.com/viewthread.php?tid=2065
因为gmail有ssl证书...所以你普通邮件发送是不成功的...
但是在服务器上测试出现:Could not connect to SMTP host本地是windows 服务器是liunx这种情况一般是什么原因?难道是服务器上的防火墙引起的?
http://hi.baidu.com/kinomn/blog/item/6f54b0957a470f007bf480f3.html
在我本机测试成功,不是服务器上。 哈,你那个贴,在我提问之前,有看过,所以才问下各位是不是服务器的防火墙引起的问题。因为是虚拟主机,不是个人服务器,VPS,且在美国,所以没啥权限。