In this example, we will show how to send an email message to someone in PHP.
PHP Code:
<?php
echo "<html><body>";
mail ("karn@nucleus.com", "Subject", "Hello!");
echo "Sending mail...";
echo "</body></html>";
?>
It is that simple!
The PHP mail function has up to four parameters. The first parameter is the recipient of the message. The second parameter is the subject of the email message. The third parameter is the body of the message. And the fourth parameter is optional, which will be covered on the next page.
If the above example does not work when you view it in your browser then the Sendmail variable in your PHP setup file is probably not set correctly. In UNIX, it should be set to something like '/usr/sbin/sendmail -t'. Consult your PHP documentation for more in depth instructions.
Advanced Example
Here we will show the full capabilities of the PHP mail function.
PHP Code:
<?php
echo "<html><body>";
$recipient = "Kris Arndt <karn@nucleus.com>,npl@nucleus.com";
$subject = "Testing the mail function";
$message = "Hello!\n\nThis is the body of the message.\n\n";
$extra = "From: kris@phpworld.com\r\nReply-To: karn@nucleus.com\r\n";
mail ($recipient, $subject, $message, $extra);
echo "Sending mail...";
echo "</body></html>";
?>
We send an email to two people this time, by putting two email addresses in the recipient field and separating them with commas.
The fourth parameter holds extra headers for the email. We specify who the email was from and who the recipient should reply to. When entering multiple headers, separate them with the line feed and new line combination ('\r\n').
自由广告区 |
分类导航 |
邮件新闻资讯: IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮 电子邮箱 | 反垃圾邮件|邮件客户端|网络安全 行业数据 | 邮件人物 | 网站公告 | 行业法规 网络技术: 邮件原理 | 网络协议 | 网络管理 | 传输介质 线路接入 | 路由接口 | 邮件存储 | 华为3Com CISCO技术 | 网络与服务器硬件 操作系统: Windows 9X | Linux&Uinx | Windows NT Windows Vista | FreeBSD | 其它操作系统 邮件服务器: 程序与开发 | Exchange | Qmail | Postfix Sendmail | MDaemon | Domino | Foxmail KerioMail | JavaMail | Winwebmail |James Merak&VisNetic | CMailServer | WinMail 金笛邮件系统 | 其它 | 反垃圾邮件: 综述| 客户端反垃圾邮件|服务器端反垃圾邮件 邮件客户端软件: Outlook | Foxmail | DreamMail| KooMail The bat | 雷鸟 | Eudora |Becky! |Pegasus IncrediMail |其它 电子邮箱: 个人邮箱 | 企业邮箱 |Gmail 移动电子邮件:服务器 | 客户端 | 技术前沿 邮件网络安全: 软件漏洞 | 安全知识 | 病毒公告 |防火墙 攻防技术 | 病毒查杀| ISA | 数字签名 邮件营销: Email营销 | 网络营销 | 营销技巧 |营销案例 邮件人才:招聘 | 职场 | 培训 | 指南 | 职场 解决方案: 邮件系统|反垃圾邮件 |安全 |移动电邮 |招标 产品评测: 邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端 |