php 发送 Email

来源:互联网 发布:数组删除指定位置 编辑:程序博客网 时间:2024/06/10 03:49
  1. < ?php   
  2. require("mail/class.phpmailer.php");//调用   
  3. $mail = new PHPMailer();//实例化phpmailer   
  4. $address = "mailxi@126.com";//接收邮件的邮箱   
  5. $mail->IsSMTP(); // 设置发送邮件的协议:SMTP   
  6. $mail->Host = "smtp.163.com"; // 发送邮件的服务器   
  7. $mail->SMTPAuth = true; // 打开SMTP   
  8. $mail->Username = "我的账户"; // SMTP账户   
  9. $mail->Password = "我的密码"; // SMTP密码   
  10. $mail->From = "mailxi@163.com";   
  11. $mail->FromName = "peng";   
  12. $mail->AddAddress("$address", "");   
  13. //$mail->AddAddress(""); // name is optional   
  14. //$mail->AddReplyTo("", "");   
  15. //$mail->WordWrap = 50; // set word wrap to 50 characters   
  16. //$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments   
  17. //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name   
  18. //$mail->IsHTML(true); // set email format to HTML   
  19. $mail->CharSet = "UTF-8";//设置字符集编码   
  20. $mail->Subject = "Sinopf的测试邮件";   
  21. $mail->Body = "Hello,Sinopf的测试邮件";//邮件内容(可以是HTML邮件)   
  22. $mail->AltBody = "This is the body in plain text for non-HTML mail clients";   
  23. if(!$mail->Send())   
  24. {   
  25. echo "Message could not be sent. < p>";   
  26. echo "Mailer Error: " . $mail->ErrorInfo;   
  27. exit;   
  28. }   
  29. echo "Message has been sent";//发送成功显示的信息   

 

配置 php.ini 

 

[mail function]
; For Win32 only.
SMTP = smtp.qq.com
smtp_port = 25

; For Win32 only.
sendmail_from = xxxx@qq.com

 

 

然后需要下载 phpmailer 工具包

 

将 class.phpmailer.php class.pop3.php class.smtp.php 

 

三个文件放到 源文件中。(同一目录)

 

原创粉丝点击