Table of Contents
phpmailer Unit Test
Home php教程 php手册 php中用phpmailer发送邮件

php中用phpmailer发送邮件

Jun 06, 2016 pm 07:50 PM
l php phpmailer send Enter mail

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 在php中提供了一个发送邮件的函数mail函数,它可以在程序中直接发送电子邮件,不过它要求服务器支持sendmail 或者必须设置一台不需要中继的邮件发送服务器,但现在要找到一台不需要身份验证的邮件发

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  在php中提供了一个发送邮件的函数mail函数,它可以在程序中直接发送电子邮件,不过它要求服务器支持sendmail

  或者必须设置一台不需要中继的邮件发送服务器,但现在要找到一台不需要身份验证的邮件发送中继几乎不可能。

  所以使用mail函数往往无法成功发送email.

  自己如果熟悉SMTP协议,结合socket功能就可以编写高效稳定的邮件发送程序,但对一般用户来说太困难。好在互联网上已经有很多别人编写好的邮件发送模块,我们只需要下载后简单调用即可,十分方便。

  在此我们给用户推荐一个php下功能十分强大,易用且免费的SMTP类模块-PHPMailer,

  PHPMailer是一个用于发送电子邮件的PHP函数包。它提供的功能包括:

  *.在发送邮时指定多个收件人,抄送地址,暗送地址和回复地址

  *.支持多种邮件编码包括:8bit,base64,binary和quoted-printable

  *.支持SMTP验证

  *.支持冗余SMTP服务器

  *.支持带附件的邮件和Html格式的邮件

  *.自定义邮件头

  *.支持在邮件中嵌入图片

  *.调试灵活

  *.经测试兼容的SMTP服务器包括:Sendmail,qmail,Postfix,Imail,Exchange等

  *.可运行在任何平台之上

  下载该组件后,按如下示例编写代码即可实现php在线发送邮件。

  一:html程序

  

  

phpmailer Unit Test

  请你输入收信的邮箱地址:

  

  

  邮箱地址:

  

  

  

  

  

  二:PHP程序

  require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录

  $mail = new PHPMailer(); //建立邮件发送类

  $address = $_POST['address'];

  $mail->IsSMTP(); // 使用SMTP方式发送

  $mail->Host = "mail.xxxxx.com"; // 您的企业邮局域名

  $mail->SMTPAuth = true; // 启用SMTP验证功能

  $mail->Username = "user@xxxx.com"; // 邮局用户名(请填写完整的email地址)

  $mail->Password = "******"; // 邮局密码

  $mail->From = "user@xxxx.com"; //邮件发送者email地址

  $mail->FromName = "您的名称";

  $mail->AddAddress("$address", "");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")

  //$mail->AddReplyTo("", "");

  //$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件

  //$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式

  $mail->Subject = "PHPMailer测试邮件"; //邮件标题

  $mail->Body = "Hello,这是测试邮件"; //邮件内容

  $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略

  if(!$mail->Send())

  {

  echo "邮件发送失败。

";

  echo "错误原因: " . $mail->ErrorInfo;

  exit;

  }

  echo "邮件发送成功";

  ?>

php中用phpmailer发送邮件

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

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

See all articles