Home  >  Article  >  Backend Development  >  phpmail class send mail function code_PHP tutorial

phpmail class send mail function code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:20:00763browse

With the phpmail class, you don't have to worry. This is a class written by a foreigner, so we just "use it". The following is a function written based on the send() method in this class:

Copy code The code is as follows:

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 to use gb2312 Chinese encoding
$mail->IsSMTP(); //Set to use SMTP to send emails
$mail->Host = "smtp.qq.com"; //Set the address of the mail server
$mail-> ;Port = 25; //Set the port of the mail server, the default is 25
$mail->From = $from; //Set the sender's email address
$mail->FromName = "" ; //Set the sender's name
$mail->SMTPAuth = true; //Set whether SMTP requires password verification, true means it is required
$mail->Username = $from; //Set to send Mailbox
$mail->Password = ""; //Set the password for the mailbox
$mail->Subject = $title; //Set the title of the mail
$mail->AltBody = "text/html"; // optional, comment out and test
$mail->Body = $content; //Set the email content
$mail->IsHTML(true); //Set the content Whether it is html type
$mail->WordWrap = 50; //Set the number of characters in each line
$mail->AddReplyTo("Address", "Name"); //Set the recipient of the reply The person's address
$mail->AddAddress($to,"Star Model Training"); //Set the recipient's address
if ($attachment != '') //Set the attachment
{
$mail->AddAttachment($attachment, $attachment);
}
if(!$mail->Send())
{
return false;
} else {
return true;
}
}

Usually use QQ mailbox, because QQ mailbox is easy to open SMTP and POP3 services, and it is free. Please note that The content format and encoding of the email.
PHPMail.class.php class, click to download!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325160.htmlTechArticleWith the phpmail class, you don’t have to worry. This is a class written by a foreigner, so we just "use it". The following is a function written based on the send() method in this class...
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