Home php教程 php手册 php PEAR mail发送邮件实例

php PEAR mail发送邮件实例

May 25, 2016 pm 04:49 PM
mail pear send email

phppear mail发送邮件实例--> 

<!doctype html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=gb2312" /> 
<title>php发送邮件</title> 
</head> 
<body> 
<table width="611" height="200" border="1"> 
  <tr> 
<td width="601"><form id="form1" name="form1" method="post" action="send.php"> 
  <table width="600" height="240" border="0" cellpadding="0" cellspacing="0"> 
<tr> 
  <td width="102" height="28">收件人地址</td> 
  <td width="213"><input name="to" type="text" id="to" /></td> 
  <td width="84">发送人地址</td> 
  <td width="201"><input name="from" type="text" id="from" value="cert@163.com" /></td> 
</tr> 
<tr> 
  <td height="33">发送人用户名</td> 
  <td><input name="name" type="text" id="username" value="cert" /></td> 
  <td>邮箱密码</td> 
  <td><input name="password" type="password" id="password" value="***" /></td> 
</tr> 
<tr> 
  <td height="27">smtp服务器</td> 
  <td><input name="smtp" type="text" id="smtp" value="smtp.163.com" /></td> 
  <td colspan="2">注:163邮箱smtp为: smtp.163.com</td> 
  </tr> 
<tr> 
  <td height="26">标题</td> 
  <td colspan="3"><input name="subject" type="text" id="subject" value="cert测试php发送邮件" size="50" /></td> 
  </tr> 
<tr> 
  <td height="69">内容</td> 
  <td colspan="3"><textarea name="content" cols="50" rows="6" id="content">计算机紧急响应组欢迎你! 
http://www.phprm.com 
组织网站即将进行改版</textarea></td> 
  </tr> 
<tr> 
 
  <td> </td> 
  <td align="right"><input type="submit" name="submit" value="发送" /></td> 
  <td> </td> 
  <td> </td> 
</tr> 
  </table> 
<p>说明:我用163的邮箱发给 163 或 126 的邮箱立刻就能收到。大家试试。</p> 
</form> 
</td> 
  </tr> 
</table> 
</body> 
</html> 
<?php
require_once &#39;mail.php&#39;;
$conf[&#39;mail&#39;] = array(
    &#39;host&#39; => &#39;smtp.126.com&#39;, //smtp服务器地址
    &#39;auth&#39; => true, //true表示smtp服务器需要验证,false不需要
    &#39;username&#39; => &#39;liangbowen&#39;, //用户名
    &#39;password&#39; => &#39;******&#39;
    //密码
    
);
//发送邮件
$headers[&#39;from&#39;] = &#39;liangbowen@126.com&#39;; //发信地址
$headers[&#39;to&#39;] = &#39;liangbowen@hotmail.com&#39;; //收信地址
$headers[&#39;subject&#39;] = &#39;test mail send by php bowen.mvbb.com&#39;; //邮件标题
$mail_object = & mail::factory(&#39;smtp&#39;, $conf[&#39;mail&#39;]);
//邮件正文
$body = "这是一封自己发给自己的邮件。";
$mail_res = $mail_object->send($headers[&#39;to&#39;], $headers, $body); //发送
if (pear::iserror($mail_res)) { //检测错误
    die($mail_res->getmessage());
} else {
    echo "send successful!";
}
?>
Copy after login


文章链接:

随便收藏,请保留本文地址!

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 尊渡假赌尊渡假赌尊渡假赌

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 email using Flask-Mail How to send email using Flask-Mail Aug 02, 2023 am 10:17 AM

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 Alibaba Cloud interface to implement email sending function Python connects to Alibaba Cloud interface to implement email sending function Jul 05, 2023 pm 04:33 PM

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? How to send mail using PHP queue? Sep 13, 2023 am 08:00 AM

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

PHP Mail Usage Guide: Simple and easy-to-understand tutorial for sending emails PHP Mail Usage Guide: Simple and easy-to-understand tutorial for sending emails Mar 28, 2024 pm 12:12 PM

PHP is a scripting language widely used for developing web applications. It provides many functions for handling email sending. This article will introduce you to how to use the email sending function in PHP and provide specific code examples. 1. Preparation Before using PHP to send emails, you first need to ensure that your server has been configured to send emails. Generally speaking, you need an SMTP server to send emails. You can use the SMTP server provided by your email provider, such as Gmail's SMTP

How to use Java's built-in mail API to implement email sending function How to use Java's built-in mail API to implement email sending function May 11, 2023 pm 12:49 PM

Requirements: To send emails, use the jdk native API - java.mail to implement the email function. The following code can send emails, taking qq mailbox as an example packagecom.example.demo.emailInfo; importjavax.mail.Message; importjavax.mail.MessagingException; importjavax.mail.Session;importjavax.mail.Transport;importjavax.mail.internet.Inte

How to send emails using PHP email() function How to send emails using PHP email() function May 22, 2023 pm 03:10 PM

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.

See all articles