Home  >  Article  >  Backend Development  >  Sending emails using PHPMail class

Sending emails using PHPMail class

WBOY
WBOYOriginal
2016-07-25 08:45:19991browse
  1. function send_mail ($title,$content,$from,$to,$charset='gbk',$attachment ='')
  2. {
  3. include '/class/PHPMail.class.php'; //Baidu Double click
  4. header('Content-Type: text/html; charset='.$charset);
  5. $mail = new PHPMailer();
  6. $mail->CharSet = $charset; //Set to use gb2312 Chinese encoding
  7. $mail->IsSMTP(); //Set to use SMTP to send emails
  8. $mail->Host = "smtp.qq.com"; //Set the address of the mail server
  9. $mail->Port = 25; //Set the port of the mail server, the default is 25
  10. $mail->From = $from; //Set the sender's email address
  11. $mail->FromName = ""; //Set the sender's name
  12. $mail->SMTPAuth = true; //Set whether SMTP requires password verification, true means it is required
  13. $mail->Username = $from; //Set the email address for sending emails
  14. $mail->Password = "" ; //Set the email password
  15. $mail->Subject = $title; //Set the email title
  16. $mail->AltBody = "text/html"; // optional, comment out and test
  17. $mail- >Body = $content; //Set the email content
  18. $mail->IsHTML(true); //Set whether the content is html type
  19. $mail->WordWrap = 50; //Set the number of characters per line
  20. $mail->AddReplyTo("10000@qq.com","China's Strongest Voice"); //Set the address of the reply recipient
  21. $mail->AddAddress($to,"China's Strongest Voice" ); //Set the recipient's address
  22. if ($attachment != '') //Set the attachment
  23. {
  24. $mail->AddAttachment($attachment, $attachment);
  25. }
  26. if(!$mail-> ;Send())
  27. {
  28. return false;
  29. } else {
  30. return true;
  31. }
Copy code

Send email, PHPMail


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn