search
PHP email sending caseJun 06, 2018 pm 05:00 PM
php email sending

This article mainly introduces PHP email sending cases. Interested friends can refer to it. I hope it will be helpful to everyone.

The role of the mail() function: Connect to the mail server, use the smtp protocol, interact with the server and send mail.

Note:

1. The mail function does not support the esmtp protocol, that is, it can only cast directly and cannot log in.

2. From the above article, we can only send directly to the final receiving server address. And this address is specified in PHP.ini, so we want to use the mail() function to aseoev@ If 163.com sends an email, we need to ---

1) Query the address of the 163 mail server

2) Write the address to php. ini to

php example code is as follows:

SMTP = 163mx02.mxmail.netease.com 
sendmail_from = wusong@192.168.1.100 
var_dump(mail('12345678@qq.com','from php mail function','very intresting'));

But to use the mail function that comes with php to send emails, we need to install one in linux Only sendmail component can be used, otherwise it cannot be used.

If you don’t have this sendmail component, we can use the phpmailer function to operate it. The example code is as follows:

<?php 
 
 require(&#39;./PHPMailer/class.phpmailer.php&#39;); 
 
 $phpmailer = new PHPMailer(); 
 
 $phpmailer->IsSMTP(); 
 
 $phpmailer->Host = &#39;smtp.163.com&#39;; 
 $phpmailer->SMTPAuth = true; 
 $phpmailer->Username = &#39;&#39;; 
 $phpmailer->Password = &#39;&#39;; 
 
 $phpmailer->CharSet = &#39;utf-8&#39;; 
 $phpmailer->From = &#39;&#39;; 
 $phpmailer->FromName = &#39;&#39;; 
 $phpmailer->Subject = &#39;&#39;; 
 $phpmailer->Body = &#39;&#39;; 
 
 $phpmailer->AddAddress(&#39;never_kiss@163.com&#39;,&#39;Aseoe&#39;); 
 
 echo $phpmailer->send()?&#39;发送成功&#39;:&#39;发送失败&#39;; 
 
?>

There is no content above. Let’s take a look at the code with content. As follows:

<?php 
 
/** 
用PHPMailer类来发信 


步骤: 
0: 引入 
1: 实例化 
2: 配置属性 
3: 调用发送 
**/ 
require(&#39;./PHPMailer/class.phpmailer.php&#39;); 
$phpmailer = new PHPMailer(); 
 
/* 
设置phpmailer发信用的方式 
可用用win下mail()函数来发 
可以用linux下sendmail,qmail组件来发 
可以利用smtp协议登陆到某个账户上,来发 
*/ 
$phpmailer->IsSMTP(); // 用smtp协议来发 
$phpmailer->Host = &#39;smtp.163.com&#39;; 
$phpmailer->SMTPAuth = true; 
$phpmailer->Username = &#39;&#39;; //发送邮箱的账号(用163邮箱发信的账号) 
$phpmailer->Password = &#39;&#39;; //发送邮箱的密码 
// 可以发信了 
$phpmailer->CharSet=&#39;utf-8&#39;; 
$phpmailer->From = &#39;never_4ill@163.com&#39;; 
$phpmailer->FromName = &#39;neverkill&#39;; 
$phpmailer->Subject = &#39;Superstart Aseoe&#39;; 
$phpmailer->Body = &#39;脚本之家(http://www.jb51.net 专注前端开发与编程设计.&#39;; 
//设置收信人 
$phpmailer->AddAddress(&#39;never_4ill@163.com&#39;,&#39;neverkill&#39;); 
// 添加一个抄送 
$phpmailer->AddCC(&#39;1234567&#39;,&#39;Aseoe&#39;); 
// 发信 
echo $phpmailer->send()?&#39;ok&#39;:&#39;fail&#39;;

Add a method using the above example:

Directly decompress the phpmailer compressed package and put it in the root directory to run, and put the file directly into the local wamp In the root directory, run 02.php to send the email (assuming the php file is executable) - (if not, create a folder in the root directory and repeat the operation) http://localhost/02.php.

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

php uses ffmpeg to implement the method of adding text subtitles to videos

php The definition of parse_str() function and Detailed explanation of usage examples

php method of randomly selecting values ​​from arrays and simple examples

The above is the detailed content of PHP email sending case. For more information, please follow other related articles on the PHP Chinese website!

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
PHP实现邮件发送及接收的方法PHP实现邮件发送及接收的方法Jun 18, 2023 am 08:38 AM

PHP是一种广泛使用的服务器端脚本语言,在开发Web应用程序时经常用到。它可以轻易地发送和接收电子邮件,这让开发者可以快速构建自己的邮件系统。在本文中,我们将探讨如何使用PHP实现邮件发送和接收的方法。一、发送电子邮件PHP提供了发送电子邮件的许多函数,最常用的是使用SMTP服务器发送电子邮件的PHPMailer类。这个类是使用PHP编写的开源库,具有广泛的

PHP邮件发送方法及常见问题汇总PHP邮件发送方法及常见问题汇总Jun 08, 2023 pm 10:57 PM

在互联网时代,邮件已经成为人们生活、工作中不可或缺的一个部分。PHP作为一种广泛应用于Web开发领域的语言,邮件发送在Web应用中也是必不可少的。本文将详细介绍PHP邮件发送的相关内容和常见问题汇总。一、PHP邮件发送方法PHPmailer库PHPmailer是一种功能强大的PHP邮件发送类库,它可以轻松地发送HTML格式和纯文本格式的邮件。使用PHPmai

PHP邮件发送指南:如何使用mail函数发送邮件PHP邮件发送指南:如何使用mail函数发送邮件Jul 30, 2023 pm 10:13 PM

PHP邮件发送指南:如何使用mail函数发送邮件在Web开发中,经常会遇到需要发送邮件的情况,例如注册成功后自动发送欢迎邮件,或者忘记密码后重置密码邮件等。而在PHP中,我们可以使用mail函数来实现邮件的发送功能。本篇文章将教你如何使用mail函数发送邮件。一、准备工作在使用mail函数发送邮件之前,我们需要确保服务器已经配置好了SMTP服务,并且安装了s

如何使用PHP通过邮箱发送电子邮件?如何使用PHP通过邮箱发送电子邮件?Sep 19, 2023 am 09:46 AM

如何使用PHP通过邮箱发送电子邮件?随着互联网的发展,电子邮件已经成为了人们日常生活和工作中不可或缺的一部分。而通过编程语言实现自动发送电子邮件的功能,则能极大地提高工作效率和便捷性。在PHP中,我们可以使用SMTP协议通过邮箱发送电子邮件。接下来,我将为大家介绍如何在PHP中实现通过邮箱发送电子邮件的具体方法,并给出代码示例。步骤一:安装必要的库在PHP中

PHP邮件发送函数详细解析:mail、smtp、PHPMailer等函数的邮件发送操作指南PHP邮件发送函数详细解析:mail、smtp、PHPMailer等函数的邮件发送操作指南Nov 18, 2023 pm 05:20 PM

PHP邮件发送函数详细解析:mail、smtp、PHPMailer等函数的邮件发送操作指南,需要具体代码示例一、引言在现代社会中,电子邮件已经成为人们沟通、交流信息的重要工具之一。在Web开发中,我们经常会遇到发送邮件的需求,无论是用户注册验证、密码重置,还是系统通知和营销活动,都需要用到邮件发送功能。PHP作为一种强大的脚本语言,提供了多种发送邮件的函数和

如何处理PHP表单中的邮件发送和接收如何处理PHP表单中的邮件发送和接收Aug 11, 2023 am 08:30 AM

如何处理PHP表单中的邮件发送和接收邮件是现代通讯的重要方式之一,通过在网站的表单中添加邮件发送和接收功能,可以使网站更加实用和互动。本文将介绍如何使用PHP处理表单中的邮件发送和接收。邮件发送在处理邮件发送前,首先确保服务器已经配置好了邮件发送功能。一般来说,邮件发送涉及到SMTP服务器的设置,可以从网络服务提供商或者网络管理员处获取SMTP服务器的地址、

如何使用PHP实现邮件到达和读取功能?如何使用PHP实现邮件到达和读取功能?Sep 19, 2023 pm 01:29 PM

如何使用PHP实现邮件到达和读取功能?随着互联网的迅速发展,电子邮件已经成为人们日常生活和工作中不可缺少的一部分。使用PHP语言来实现邮件到达和读取功能,可以帮助我们更加高效地管理和处理邮件。下面我将详细介绍如何使用PHP来实现邮件到达和读取功能,包括配置SMTP、发送邮件和读取邮件。配置SMTP要发送和读取邮件,首先需要配置SMTP参数。SMTP(Simp

使用PHP来发送电子邮件使用PHP来发送电子邮件Jun 11, 2023 am 08:46 AM

随着互联网和电子邮件的普及,越来越多的人开始使用电子邮件作为主要的沟通工具。PHP是一种流行的服务器端编程语言,也可以用来发送电子邮件。在本文中,我们将介绍如何使用PHP来发送电子邮件。配置SMTP服务器首先,我们需要配置SMTP服务器。SMTP(SimpleMailTransferProtocol)是电子邮件传输的标准协议。大多数邮件服务提供商都会提

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)