动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 两个PHP发送邮件的例子

作者来源: 
阅读 1529 人次 , 2006-3-29 4:19:00 


send mail in php

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').

 本文Tags邮件  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:NT下基于邮件服务软件(IMAIL)的邮件发送程序--(网络版)
· 下一篇:“收发”邮件的一个程序
· 如何压缩一段文本后存入mysql中
· MySQL数据导入与导出
· 用PHP控制您的浏览器cache
· SMTP协议原始命令码和工作原理
· PHP动态图像的创建


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077