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'
}//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