The phpmail class sends the mail function code

  • 2020-05-16 06:25:12
  • OfStack

With the class phpmail, you don't have to worry. This is a class written by a foreigner, and we will just "bring it to you". Here is a function based on the send() method in this class:
 
function send_mail ($title,$content,$from,$to,$charset='gbk',$attachment ='') 
{ 
include '/class/PHPMail.class.php'; 
header('Content-Type: text/html; charset='.$charset); 
$mail = new PHPMailer(); 
$mail->CharSet = $charset; // Set using gb2312 Chinese code  
$mail->IsSMTP(); // Set using SMTP Way to send mail  
$mail->Host = "smtp.qq.com"; // Set the address of the mail server  
$mail->Port = 25; // Set the port of the mail server, by default 25 
$mail->From = $from; // Set the email address of the sender  
$mail->FromName = ""; // Set the sender's name  
$mail->SMTPAuth = true; // Set up the SMTP Do you need password verification? true Said need  
$mail->Username = $from; // Set the mailbox to send the email  
$mail->Password = ""; // Set the mailbox password  
$mail->Subject = $title; // Set the subject line of the email  
$mail->AltBody = "text/html"; // optional, comment out and test 
$mail->Body = $content; // Set email content  
$mail->IsHTML(true); // Sets whether the content is html type  
$mail->WordWrap = 50; // Sets the number of characters per line  
$mail->AddReplyTo(" address "," The name "); // Set the address of the recipient of the reply  
$mail->AddAddress($to," Star model training "); // Set the receiving address  
if ($attachment != '') // Set up attachment  
{ 
$mail->AddAttachment($attachment, $attachment); 
} 
if(!$mail->Send()) 
{ 
return false; 
} else { 
return true; 
} 
} 

Generally, QQ email is used, because QQ email is easy to open SMTP and POP3 services, and it is free, paying attention to the content format and encoding of the email.
PHPMail.class.php, download it!

Related articles: