Home Backend Development PHP Tutorial Introduction to how to send emails using PHPMailer (with code)

Introduction to how to send emails using PHPMailer (with code)

Aug 20, 2018 pm 04:19 PM
phpmailer

This article brings you an introduction to the method of sending emails with PHPMailer (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Please download PHPmailer from github, or directly from Baidu. It is not difficult. Although there are a lot of things in PHPmailer, we only need

PHPMailer.class.php

PHPMailerAutoload .class.php

SMTP.class.php

Then install phpmailer through composer. This is an example I wrote during testing. It was written directly in the native .php file. In fact, There are also some parameters that are useless, but I have not tested them. Friends are welcome to give advice

Although php provides the mail() function, I do not know how to do it and have not studied it, and PHPMailer is a good one The email sending tool is also very simple to use!

<?php
include("class.phpmailer.php");
include("class.smtp.php");
//实例化
$mail = new PHPMailer();
//设置smtp参数
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPKeepAlive = true;
//$mail->SMTPSecure = "SSL";
$mail->Host = "smtp.163.com";
$mail->Port = 25;
//填写你的邮箱账号和密码
$mail->Username = "18681613053@163.com";
$mail->Password = "*********";
//设置发送方,最好不要伪造地址
$mail->From = "18681613053@163.com";
$mail->FromName = "阳台大爷";
//标题,内容,和备用内容
$mail->Subject = "163email";
$mail->Body = "163email body";
$mail->AltBody = "163email!!!纯文本";//如果邮件不支持HTML格式,则替换成该纯文本模式邮件
$mail->WordWrap = 50; // 设置邮件每行字符数
//$mail->MsgHTML($body);
//设置回复地址
$mail->AddReplyTo("18681613053@163.com","yy");
//添加附件,此处附件与脚本位于相同目录下,否则填写完整路径
//$mail->AddAttachment("attachment.zip");
//设置邮件接收方的邮箱和姓名
$mail->AddAddress("704203193@qq.com","FirstName LastName");
//使用HTML格式发送邮件
$mail->IsHTML(true);
//通过Send方法发送邮件,根据发送结果做相应处理
if(!$mail->Send()) {
echo "发送失败: " . $mail->ErrorInfo;
} else {
echo "邮件已经成功发送";
}
?>
Copy after login

Related recommendations:

Use PHPMailer to send emails, phpmailer to send emails

A simple way to send emails with phpmailer (with phpmailer source code download ), phpmailer source code download

The above is the detailed content of Introduction to how to send emails using PHPMailer (with code). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP methods and steps for sending emails to multiple people using PHPMailer PHP methods and steps for sending emails to multiple people using PHPMailer May 22, 2023 pm 06:10 PM

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 PHP development practice: Use PHPMailer to send emails to users in the MySQL database Aug 05, 2023 pm 06:21 PM

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 send HTML mail with embedded images using PHP and PHPMAILER? How to send HTML mail with embedded images using PHP and PHPMAILER? Jul 22, 2023 am 11:29 AM

How to send HTML mail with embedded images using PHP and PHPMAILER? HTML email is a richer and more personalized form of email that can insert pictures, links and styles into the email. Embedded images refer to sending images directly as part of the email in the HTML email instead of sending them as attachments. In PHP, we can use PHPMAILER to send HTML emails with embedded images. PHPMAILER is a powerful PHP email sending library

PHP and PHPMAILER: How to implement anti-spam function for email sending? PHP and PHPMAILER: How to implement anti-spam function for email sending? Jul 22, 2023 am 11:46 AM

PHP and PHPMAILER: How to implement anti-spam function for email sending? Introduction: In the Internet age, email has become an indispensable part of our daily life and work. However, with the popularity and use of email, the problem of spam has become increasingly serious, causing a lot of trouble to users. In order to solve this problem, this article will introduce how to use PHP and PHPMailer library to implement the anti-spam function of email sending. 1. Understand spam. Spam refers to those unsolicited

PHP methods and precautions for sending attachment emails using the PHPMailer library PHP methods and precautions for sending attachment emails using the PHPMailer library May 21, 2023 pm 06:12 PM

PHP methods and precautions for sending attachment emails using the PHPMailer library. Email has become a very important way of communication in modern life. In many development projects, we need to use code to automatically send emails. At this time, the PHPMailer library is our best choice. PHPMailer is a library dedicated to sending emails in PHP. It can easily send emails, including HTML-formatted emails and attachments. This article will focus on how to send emails with attachments in the PHPMailer library.

Mastering PHP and PHPMAILER: How to implement the automatic reply function for email sending? Mastering PHP and PHPMAILER: How to implement the automatic reply function for email sending? Jul 22, 2023 am 11:57 AM

Mastering PHP and PHPMAILER: How to implement the automatic reply function for email sending? In modern society, email has become one of the important ways for people to communicate every day. Many websites or companies need to communicate with users through emails, and automatic reply to emails has become very important. This article will introduce how to use PHP and the PHPMailer library to implement the automatic reply function for email sending. Step 1: Get the user’s email information First, we need to get the user’s email information. On a website or application, use

How to use PHPMailer with CakePHP? How to use PHPMailer with CakePHP? Jun 04, 2023 pm 01:10 PM

CakePHP is a PHP open source framework based on the MVC model, designed to provide developers with an efficient, scalable, and easy-to-maintain Web application development environment. Among them, the mail function has always been one of the important components of Web applications. In order to facilitate developers to use the mail function, the PHPMailer class library has been encapsulated in CakePHP. PHPMailer is a commonly used email sending library that supports functions such as sending HTML emails, attachments, carbon copy, mail queue, and SMTP verification. Book

How to send HTML mail with pictures using PHP and PHPMAILER? How to send HTML mail with pictures using PHP and PHPMAILER? Jul 21, 2023 am 09:21 AM

How to send HTML emails with images using PHP and PHPMailer? Email plays an important role in modern communication, but sending HTML emails with images may confuse some PHP developers. In this article, we will introduce how to use PHP and PHPMailer to send HTML emails with images. We'll provide code examples to help you better understand how to achieve this. First, we need to make sure that the PHPMailer library is installed in our project

See all articles