Table of Contents
PHP mail,phpmail
PHP mail() 函数
语法
PHP 简易 E-Mail
PHP Mail Form
例子解释:
Home php教程 php手册 PHP mail,phpmail

PHP mail,phpmail

Jun 13, 2016 am 08:40 AM
e-mail

PHP mail,phpmail

PHP 允许您从脚本直接发送电子邮件。

PHP mail() 函数

PHP mail() 函数用于从脚本中发送电子邮件。

语法

mail(to,subject,message,headers,parameters)
Copy after login
参数描述
to 必需。规定 email 接收者。
subject 必需。规定 email 的主题。注释:该参数不能包含任何新行字符。
message 必需。定义要发送的消息。应使用 LF (\n) 来分隔各行。
headers

可选。规定附加的标题,比如 From、Cc 以及 Bcc。

应当使用 CRLF (\r\n) 分隔附加的标题。

parameters 可选。对邮件发送程序规定额外的参数。

注释:PHP 需要一个已安装且正在运行的邮件系统,以便使邮件函数可用。所用的程序通过在 php.ini 文件中的配置设置进行定义。请在我们的 PHP Mail 参考手册阅读更多内容。

PHP 简易 E-Mail

通过 PHP 发送电子邮件的最简单的方式是发送一封文本 email。

在下面的例子中,我们首先声明变量($to, $subject, $message, $from, $headers),然后我们在 mail() 函数中使用这些变量来发送了一封 e-mail:

<?<span>php
</span><span>//</span><span> 何问起 hovertree.com</span>
<span>$to</span> = "hello@hovertree.net"<span>;
</span><span>$subject</span> = "Test mail"<span>;
</span><span>$message</span> = "Hello! This is a simple email message."<span>;
</span><span>$from</span> = "hello@hovertree.net"<span>;
</span><span>$headers</span> = "From: <span>$from</span>"<span>;
</span><span>mail</span>(<span>$to</span>,<span>$subject</span>,<span>$message</span>,<span>$headers</span><span>);
</span><span>echo</span> "Mail Sent."<span>;

</span>?>
Copy after login

PHP Mail Form

通过 PHP,您能够在自己的站点制作一个反馈表单。下面的例子向指定的 e-mail 地址发送了一条文本消息:

<html>
<body>
<!-- 何问起 hovertree.com -->
<?<span>php
</span><span>if</span> (<span>isset</span>(<span>$_REQUEST</span>['email'<span>]))
</span><span>//</span><span>if "email" is filled out, send email</span>
<span>  {
  </span><span>//</span><span>send email</span>
  <span>$email</span> = <span>$_REQUEST</span>['email'<span>] ; 
  </span><span>$subject</span> = <span>$_REQUEST</span>['subject'<span>] ;
  </span><span>$message</span> = <span>$_REQUEST</span>['message'<span>] ;
  </span><span>mail</span>( "someone@example.com", "Subject: <span>$subject</span>",
  <span>$message</span>, "From: <span>$email</span>"<span> );
  </span><span>echo</span> "Thank you for using our mail form"<span>;
  }
</span><span>else</span>
<span>//</span><span>if "email" is not filled out, display the form</span>
<span>  {
  </span><span>echo</span> "<span><form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form></span>"<span>;
  }
</span>?>

</body>
</html>
Copy after login

 

例子解释:

1)windows需要配置IIS的SMTP;linux自带sendmail组件,无需设置,直接支持mail函数发送功能

   2)php.ini中声明SMTP各项参数

   3)mail("接收地址","邮件主题","邮件内容")函数的使用

 

例1:配置本地SMTP服务器

第一步: php.ini的设置:
     SMTP = localhost
     smtp_port = 25
     sendmail_from=你的设定值
第二步:需要安装IIS自带的SMTP,在SMTP虚拟服务器上点击右键,在弹出的属性窗口里进行如下设置:
     点击“访问”选项卡,再点击“中继”,在弹出的窗口出点击“添加”,然后选“单台计算机”,添加IP地址为“127.0.0.1”,然后一

     路确定返回。

第三步:
               mail("123456@qq.com","Test mail function of PHP.","hello world! hovertree.com");
      ?>

推荐:http://www.cnblogs.com/roucheng/p/3528396.html

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)

What happens when you use Hide My Email on iPhone? What happens when you use Hide My Email on iPhone? Feb 22, 2024 pm 09:19 PM

Apple offers a privacy-focused feature called "Hide Email Address" that allows users to hide their real email addresses on apps or websites that require account registration. We've taught you how to use this feature on your iPhone, now let's take a look at what's possible when using it in your daily work. What is a hidden email address on iPhone? The purpose of the Hide Email Address feature is to protect the privacy of your email address. By providing a temporary email address for application and website registration, you do not need to directly provide a person's real email address. This feature allows you to generate multiple iCloud email addresses for signing up with different services, thus avoiding revealing your true email address.

How to sort emails by sender, subject, date, category, size in Outlook How to sort emails by sender, subject, date, category, size in Outlook Feb 19, 2024 am 10:48 AM

Outlook offers many settings and features to help you manage your work more efficiently. One of them is the sorting option that allows you to categorize your emails according to your needs. In this tutorial, we will learn how to use Outlook's sorting feature to organize emails based on criteria such as sender, subject, date, category, or size. This will make it easier for you to process and find important information, making you more productive. Microsoft Outlook is a powerful application that makes it easy to centrally manage your email and calendar schedules. You can easily send, receive, and organize email, while built-in calendar functionality makes it easy to keep track of your upcoming events and appointments. How to be in Outloo

How to implement a simple email sending program using C++? How to implement a simple email sending program using C++? Nov 02, 2023 pm 05:35 PM

How to implement a simple email sending program using C++? With the popularity of the Internet, email has become an indispensable part of people's daily life and work. In C++ programming, we can use the SMTP (SimpleMailTransferProtocol) protocol to implement a simple email sending program. This article will introduce how to write a basic email sending program using C++. First, we need to prepare some tools and libraries to implement our program. first

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

PHP email templates: customize and personalize your email content. PHP email templates: customize and personalize your email content. Sep 19, 2023 pm 01:21 PM

PHP email templates: Customize and personalize your email content With the popularity and widespread use of email, traditional email templates can no longer meet people's needs for personalized and customized email content. Now we can create customized and personalized email templates by using PHP programming language. This article will show you how to use PHP to achieve this goal, and provide some specific code examples. 1. Create an email template First, we need to create a basic email template. This template can be an HTM

What are the characteristics of email What are the characteristics of email Jan 22, 2021 pm 04:10 PM

The characteristics of email are: 1. Low cost. Email uses a store-and-forward method to gradually transmit information on the network. It is not as direct as a phone call, but the cost is lower; 2. It spreads quickly. Email combines telephone communication and postal mail. It can transmit information as fast as a phone call and can be sent to any designated destination in the world within a few seconds; 3. It is very convenient; 4. It has a wide range of communication objects and can be connected to the network in any corner of the world. User contact; 5. The information is diverse and can be in various forms such as text, images, sounds, etc.; 6. It is relatively safe.

What is an email address? How to fill it in? What is an email address? How to fill it in? Jan 05, 2024 pm 02:33 PM

The email address is a fixed format created by Ray Tomlinson: user@mail.server.name, which is similar to the address of the recipient when mailing a regular letter. In the format, user is the recipient's user name, and mail.server.name is the recipient's email server name. It can also be a domain name or an IP address represented by a decimal number. Each user's email address on the Internet is unique, which makes sending and receiving emails more convenient and accurate.

Email format Email format Apr 26, 2024 am 11:49 AM

1. The email format includes the following elements: recipient, sender, subject, body, attachment and date. 2. The recipient specifies the recipient of the email. The recipient's email address usually consists of a username and a domain name, separated by the @ symbol. 3. Sender contains the sender information of the email, including name and email address. This information is displayed in the header of the email and shows the sender's identity to the recipient. 4. The subject is a brief summary of the email content. It is usually a concise and meaningful phrase that can help the recipient quickly understand the main content of the email.

See all articles