Home >php教程 >PHP开发 >Example of sending HTML email using mail function in php

Example of sending HTML email using mail function in php

高洛峰
高洛峰Original
2016-11-29 11:35:551347browse

PHP comes with the mailbox sending function mail(). We can use this function directly to send emails. Below I will introduce some commonly used examples of email sending. The simplest one is the mail function.

For example, the code is as follows:

function send_mail($from, $to, $subject, $message)

{

if ($from == "")

{

$from = 'Memories of the Future' ';//Sender address

}//Open source software: phpfensi.com

$headers = 'MIME-Version: 1.0' . "rn";

$headers .= 'Content- type: text/html; charset=gb2312' . "rn";

$headers .= 'From: ' . $from . "rn";

mail($to, $subject, $message, $headers);

}

?>

Tips: The program to be used is defined by the configuration settings in the php.ini file. The behavior of the mail function is affected by php.ini. We must configure it first.

Name Default Description Can be changed

SMTP "localhost" Windows only: DNS name or IP address of the SMTP server. PHP_INI_ALL

smtp_port "25" Windows only: SMTP segment port number. Available since PHP 4.3. PHP_INI_ALL

sendmail_from NULL Windows only: Specifies the "from" address to be used in emails sent from PHP. PHP_INI_ALL

sendmail_path NULL Unix system-specific: Specifies the path of the sendmail program (usually /usr/sbin/sendmail or /usr/lib/sendmail) PHP_INI_SYSTEM


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