PHP uses phpmailer to send emails
phpmailer is a free php email sending plug-in. We can use phpmailer to log in to our designated email and then use this email to automatically send us emails. This free email address like 163 and Sina all support it. Okay Without further ado, let’s take a look at a phpmainer 163 email to send an email.
There is no local email server. It is a good choice to use a ready-made SMTP server to send emails. The tool used here is phpmailer (Version 5.2.0), and the SMTP servers are gmail and 163.
1. Script to send using gmail
include("class.phpmailer.php"); include("class.smtp.php"); //获取一个外部文件的内容 $mail = new PHPMailer(); $body = file_get_contents('contents.html'); $body = eregi_replace("[\]",'',$body); //设置smtp参数 $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->SMTPKeepAlive = true; $mail->SMTPSecure = "ssl"; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; //填写你的gmail账号和密码 $mail->Username = "yourname@gmail.com"; $mail->Password = "password"; //设置发送方,最好不要伪造地址 $mail->From = "yourname@gmail.com"; $mail->FromName = "Webmaster"; $mail->Subject = "This is the subject"; $mail->AltBody = $body; $mail->WordWrap = 50; // set word wrap $mail->MsgHTML($body); //设置回复地址 $mail->AddReplyTo("yourname@gmail.com","Webmaster"); //添加附件,此处附件与脚本位于相同目录下 //否则填写完整路径 $mail->AddAttachment("attachment.jpg"); $mail->AddAttachment("attachment.zip"); //设置邮件接收方的邮箱和姓名 $mail->AddAddress("toname@gmail.com","FirstName LastName"); //使用HTML格式发送邮件 $mail->IsHTML(true); //通过Send方法发送邮件 //根据发送结果做相应处理 if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; }
2. Script to send email using 163
You only need to change the SMTP configuration and account password, the SMTP configuration is as follows
//设置smtp参数 //注意这里不需要ssl协议 $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->SMTPKeepAlive = true; $mail->Host = "smtp.163.com"; $mail->Port = 25;
To pass the test in the local wampserver environment, you need to enable the php_openssl extension.
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
php methods to operate MySQL database and session dialogue
Three commonly used methods in php Tree traversal techniques
Definition and usage of the PHPZip class
The above is the detailed content of PHP uses phpmailer to send emails. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator
Generate AI Hentai for free.

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

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

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 (

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 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? 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. 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.

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 formatted emails using PHP and PHPMailer? With the development of the Internet, email has become an important tool for people's daily communication. When developing websites and applications, we often need to use PHP and PHPMailer to send emails. This article will introduce you to how to use PHP and PHPMailer to send emails in HTML format, and provide corresponding code examples. Step One: Preparation Before you begin, you need to make sure you have PHP and PHPmail installed
