PHP发送邮件是不是有系统函数?

来源:百度知道 编辑:UC知道 时间:2024/06/17 15:33:31
刚学php网页编程,PHP发送邮件是不是有系统函数?不用像asp那样要装组件吧?

HTTP 函数允许您从脚本中直接发送电子邮件。要使邮件函数可用,PHP 需要已安装且正在运行的邮件系统。要使用的程序是由 php.ini 文件中的配置设置定义的。

语法:mail(to,subject,message,headers,parameters)

参数 描述
to 必需。规定邮件的接收者。
subject 必需。规定邮件的主题。该参数不能包含任何换行字符。
message 必需。规定要发送的消息。
headers 必需。规定额外的报头,比如 From, Cc 以及 Bcc。
parameters 必需。规定 sendmail 程序的额外参数。

例子 1
发送一封简单的邮件:

<?php

$txt = "First line of text\nSecond line of text";

// 如果一行大于 70 个字符,请使用 wordwrap()。
$txt = wordwrap($txt,70);

// 发送邮件
mail("somebody@example.com","My subject",$txt);
?>例子 2
发送带有额外报头的 email:

<?php

$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$txt,$headers);
?&