phpmail类发送邮件函数代码_PHP
有了phpmail这个类,你就不用愁了。这是个外国人写的一个类,我们就只管“拿来主义”了。下面是基于这个类里面的send()方法写的一个函数:
复制代码 代码如下:
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; //设置采用gb2312中文编码
$mail->IsSMTP(); //设置采用SMTP方式发送邮件
$mail->Host = "smtp.qq.com"; //设置邮件服务器的地址
$mail->Port = 25; //设置邮件服务器的端口,默认为25
$mail->From = $from; //设置发件人的邮箱地址
$mail->FromName = ""; //设置发件人的姓名
$mail->SMTPAuth = true; //设置SMTP是否需要密码验证,true表示需要
$mail->Username = $from; //设置发送邮件的邮箱
$mail->Password = ""; //设置邮箱的密码
$mail->Subject = $title; //设置邮件的标题
$mail->AltBody = "text/html"; // optional, comment out and test
$mail->Body = $content; //设置邮件内容
$mail->IsHTML(true); //设置内容是否为html类型
$mail->WordWrap = 50; //设置每行的字符数
$mail->AddReplyTo("地址","名字"); //设置回复的收件人的地址
$mail->AddAddress($to,"星模实训"); //设置收件的地址
if ($attachment != '') //设置附件
{
$mail->AddAttachment($attachment, $attachment);
}
if(!$mail->Send())
{
return false;
} else {
return true;
}
}
一般就是用QQ邮箱了,因为QQ邮箱很容易开启SMTP和POP3服务,而且免费,注意的就是邮件的内容格式和编码。
PHPMail.class.php这个类,点击下载吧!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In web applications, it is often necessary to send emails to multiple recipients at once. PHP is a very popular web development language, and PHPMailer is a common PHP class library for sending emails. PHPMailer provides a rich interface, making sending emails in PHP applications more convenient and easy to use. In this article, we will introduce the methods and steps on how to use PHPMailer to send emails to multiple recipients. To download PHPMailer, you first need to go to the official website (

PHP development practice: Use PHPMailer to send emails to users in the MySQL database Introduction: In the construction of the modern Internet, email is an important communication tool. Whether it is user registration, password reset, or order confirmation in e-commerce, sending emails is an essential function. This article will introduce how to use PHPMailer to send emails and save the email information to the user information table in the MySQL database. 1. Install the PHPMailer library PHPMailer is

How to use Flask-Mail to send emails With the development of the Internet, email has become an important tool for people to communicate. When developing web applications, sometimes we need to send emails in specific scenarios, such as sending a welcome email after a user successfully registers, or sending a password reset email when a user forgets their password, etc. Flask is a simple and flexible Python Web framework, and Flask-Mail is an extension library for sending emails under the Flask framework. This article will introduce how to

Python connects to the Alibaba Cloud interface to implement the email sending function. Alibaba Cloud provides a series of service interfaces, including email sending services. By connecting to the Alibaba Cloud interface through a Python script, we can quickly send emails. This article will show you how to use Python scripts to connect to the Alibaba Cloud interface and implement the email sending function. First, we need to apply for the email sending service on Alibaba Cloud and obtain the corresponding interface information. In the Alibaba Cloud Management Console, select the email push service and create a new email

How to send mail using PHP queue? In modern web development, we often need to send large amounts of emails. Whether you're sending bulk emails to a large number of users or sending personalized emails based on user behavior, using queues to send emails is a great practice. Queues can help us improve the efficiency and stability of email sending, avoid excessive server load caused by sending too many emails, and can also handle scenarios where sending fails. In PHP development, we can use common queue tools such as Rab

With the development of Internet technology and the popularity of networks, more and more applications require the use of email for communication. As a popular server-side programming language, PHP naturally needs the function of sending emails in website development. As an open source PHP mail class library, PHPMailer can easily and quickly send emails in PHP programs. This article will introduce how to use PHPMailer to send emails and what to pay attention to. 1. Introduction to PHPMailer PHP

With the continuous development and popularization of the Internet, email has become an indispensable part of people's daily communication. During the website backend development process, it is often necessary to use PHP to send emails to meet functions such as email notifications and registration verification. PHP provides the email() function to send emails, and it is very simple to use. This article will introduce in detail how to use PHP's email() function to send emails. 1. SMTP configuration Before using the email() function to send emails, SMTP needs to be configured.

The complete process of sending emails using the mail function in PHP. With the development of Internet technology, email plays an increasingly important role in daily life. Sending and receiving emails has become an essential work and lifestyle for people. In website development, it is often necessary to perform various notifications, verifications, registrations, etc. through emails. This article will introduce the complete process of sending emails using the mail function in PHP. 1. The basic form of the mail function In PHP, the function used to send emails is mail().
