Use PHP's mail() function to send emails

Use PHP's mail() function to send emails

Sending emails using PHP's mail function

The mail() function connects to the mail server, interacts with the server and sends mail using the SMTP protocol

Notice:

1. The mail function does not support the esmtp protocol, that is, it can only be sent directly but not logged in

2. As we know from the previous point, we can only send directly to the final receiving server address, and this address needs to be specified in php.ini

Here we take NetEase mailbox as an example, first find the server address:

exhibit

Then write the address into php.ini, open php.ini, find mail function, fill in one of the addresses, and turn on the sender settings:

exhibit

Restart Apache and open a command prompt as an administrator:

httpd -k restart

exhibit

At this point the changes to php.ini will take effect. Now let's use the mail function:

Syntax: mail(to, subject, message, headers, parameters)

parameter describe
to Required. Specifies the email recipient.
subject Required. Specifies the subject of the email. Note: This parameter cannot contain any new line characters.
message Required. Defines the message to be sent. LF (\n) should be used to separate lines. Each line should be limited to 70 characters.
headers Optional. Specifies additional headers, such as From, Cc, and Bcc. Additional headers should be separated by CRLF (\r\n).
parameters Optional. Specifies additional parameters to the mail sending program.

The following is the code section:

<?php
$to = '[email protected]';
$sub = 'say hello';
$msg = 'hello, php!';
$from = "From: <eyes++>";
mail($to,$sub,$msg,$from);

Effect display:

exhibitexhibit

Note: Because the server address of NetEase mailbox is used in the above demonstration, and it does not provide forwarding service, you can only send emails to NetEase mailbox. If you want to send emails to QQ mailbox, you need to set the QQ mailbox server address in php.ini. If you need to send emails to any mailbox, you need to install an anonymous smtp server as a transit. Perhaps I will update the relevant content in this blog later.

Summarize

This is the end of this article about using the mail() function in PHP to implement the function of sending emails. For more relevant content about php mail() sending emails, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solution to the failure of mail function to send email in PHP
  • How to solve the garbled title when sending UTF-8 encoded Chinese emails using PHP's mail function
  • Solution to the failure of PHP mail to send mail through Windows SMTP
  • Solve the problem that 163/sohu/sina cannot receive emails sent by PHP MAIL function
  • How to send emails using PHP's own mail library

<<:  Detailed explanation of MySQL transaction processing usage and example code

>>:  Detailed explanation of common commands in Docker repository

Recommend

Vue implements weather forecast function

This article shares the specific code of Vue to r...

Install nvidia graphics driver under Ubuntu (simple installation method)

Install the nvidia graphics card driver under Ubu...

JavaScript implements changing the color of a web page through a slider

Hello everyone, today when I was looking at the H...

How to write object and param to play flash in firefox

Copy code The code is as follows: <object clas...

Getting Started with CSS3 Animation in 10 Minutes

Introduction Animation allows you to easily imple...

Summary of Seven Basic XHTML Coding Rules

1. All tags must have a corresponding end tag Prev...

Examples of using MySQL covering indexes

What is a covering index? Creating an index that ...

Text pop-up effects implemented with CSS3

Achieve resultsImplementation Code html <div&g...

Summary of the dockerfile-maven-plugin usage guide

Table of contents pom configuration Setting.xml c...

CSS to achieve the sticky effect of two balls intersecting sample code

This is an effect created purely using CSS. To pu...

How to install Tomcat-8.5.39 on centos7.6

Here is how to install Tomcat-8.5.39 on centos7.6...

Solve MySQL deadlock routine by updating different indexes

The previous articles introduced how to debug loc...

Docker data storage tmpfs mounts detailed explanation

Before reading this article, I hope you have a ba...