Home > Article > Backend Development > An example of using PHP to send emails using QQ free mailbox_PHP tutorial
An example of sending emails with PHP. Of course, sending emails requires a client email. Today’s example uses QQ free corporate email as the email address for sending emails.
01
02include "PHPMailer/class.phpmailer.php";
03function send_mail($frommail,$tomail,$subject,$body,$ccmail,$bccmail){
04$mail = new PHPMailer();
05$mail->IsSMTP();
06$mail->SMTPDebug;
07$mail->Host = "smtp.qq.com";
08$mail->SMTPAuth = true;
09$mail->Port = 25;
10$mail->Username = "admin@51yip.com";
11$mail->Password = "******";
12$mail->AddReplyTo($frommail, 'tankzhang');
13$mail->AddAddress($tomail);
14$mail->SetFrom($frommail, 'tankzhang');
15$mail->IsHTML(true);
16$mail->Subject = $subject;
17$mail->MsgHTML($body);
18if(!$mail->Send())
19{
20echo "Failed to send email.
";
21echo "Error reason: " . $mail->ErrorInfo;
22exit;
23}else{
24echo "success";
25}
26}
27?>
Call the above function to send email:
1$result= send_mail("admin@163.com","12345@qq.com","test","test","","");
Note: If you don’t have a free QQ mailbox, you can register one on the Tencent website, and then add members and DNS. If there is no DNS server, add two mx records, such as using dnspod.