Login
网站首页 > 文章中心 > 其它

php关闭mail函数_用于关闭打开的文件的PHP函数是

作者:小编 更新时间:2023-08-16 09:06:52 浏览量:97人看过

php mail函数到底怎么配置

楼主用phpmailer吧,我用过,比较简单.下面是摘的一段phpmailer配置,试试看,有什么问题再提问.

第二,确认你的服务器系统已经支持socket

,通过phpinfo();查看是否支持sockets(socket 是属于PHP扩展部分),如果显现为"enabled",那就是支持了.

第三,把文件解压到你的web服务器目录下,调用类就可以了.

首先包含class.phpmailer.php,然后创建对象,设置参数,调用成员函数.具体请见下面的示例代码:

实例1,做成函数方便调用

php

require("phpmailer/class.phpmailer.php");

function smtp_mail( $sendto_email, $subject, $body, $extra_hdrs, $user_name){

$mail = new PHPMailer();

$mail-IsSMTP(); // send via SMTP

$mail-SMTPAuth = true; // turn on SMTP authentication

$mail-Username = "yourmail"; // SMTP username 注意:普通邮件认证不需要加 @域名

$mail-Password = "mailPassword"; // SMTP password

$mail-From = "yourmail@yourdomain.com"; // 发件人邮箱

$mail-FromName = "管理员"; // 发件人

$mail-AddAddress($sendto_email,"username"); // 收件人邮箱和姓名

$mail-AddReplyTo("yourmail@yourdomain.com","yourdomain.com");

//$mail-AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件

//$mail-AddAttachment("/tmp/image.jpg", "new.jpg");

$mail-IsHTML(true); // send as HTML

// 邮件主题

$mail-Subject = $subject;

// 邮件内容

$mail-Body = "

htmlhead

meta http-equiv="Content-Language" content="zh-cn"

/head

body

I love php.

/body

/html

";

$mail-AltBody ="text/html";

if(!$mail-Send())

{

echo "邮件发送有误 p";

echo "邮件错误信息: " . $mail-ErrorInfo;

exit;

}

else {

echo "$user_name 邮件发送成功!br /";

// 参数说明(发送到, 邮件主题, 邮件内容, 附加信息, 用户名)

smtp_mail("yourmail@yourdomain.com", "欢迎使用phpmailer!", "NULL", "yourdomain.com", "username");

要注意的内容:

① 邮件的字符集设置,

③ 如果你想用它来群发邮件的话,记得修改包含文件函数,如:

改为

require_once("phpmailer/class.phpmailer.php");

否则的话会产生类的重定义.

如何通过php发送邮件?php的mail函数不能用!

支持mail的服务器 一般都是linux的 国内的好像不多

自己的电脑安装mail服务器不能往外发的 呵呵 可以自己测试用

MailClass.php >>>>>>>>>>>>

class Smtp

var $host; //主机

var $user; //SMTP认证的帐号

var $pass; //认证密码

var $debug = false; //是否显示和服务器会话信息?

var $conn;

var $result_str; //结果

var $in; //客户机发送的命令

var $from; //收件人收到邮件显示的源信箱

var $email; //真实的地址

var $to; //目标信箱

var $subject; //主题

var $body; //内容

var $error;

var $All;

function Smtp($array)

$this-host = $array['host'];

$this-port = $array['port'];

$this-email= $array['trueemail'];

$this-from = $array['from'];

$this-debug = $array['debug'];

$this-socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP);

if($this-socket){

$this-result_str = "创建SOCKET:".socket_strerror(socket_last_error());

$this-debug_show($this-result_str);

else

die("初始化失败,请检查您的网络连接和参数");

$this-conn = socket_connect($this-socket,$this-host,$this-port);

if($this-conn){

$this-result_str = "创建SOCKET连接:".socket_strerror(socket_last_error());

function debug_show($str)

if($this-debug)

echo $str."p\r\n";

function setmail($to,$subject,$body){

$this-to = $to;

$this-subject = $subject;

$this-body = $body;

$All .= "From:".$this-from."\r\n";

$All .= "To:".$this-to."\r\n";

$All .= "Subject:".$this-subject."\r\n\r\n";

$All .= $this-body;

$this-All = $All;

/**

* 发送邮件部分

* 接收邮箱数组

*/

function send($toarray,$subject,$body)

//以下是和服务器会话

$this-in = "EHLO HELO\r\n";

$this-docommand();

$this-in = "AUTH LOGIN\r\n";

$this-in = $this-user."\r\n";

$this-in = $this-pass."\r\n";

foreach( $toarray as $to ) {

$this - setmail($to,$subject,$body);

$this-in = "RSET\r\n";

$this-in = "MAIL FROM:".$this-email."\r\n";

$this-in = "RCPT TO:".$this-to."\r\n";

$this-in = "DATA\r\n";

$this-in = $this-All."\r\n.\r\n";

$this-in = "QUIT\r\n";

//结束,关闭连接

function docommand()

socket_write ($this-socket, $this-in, strlen ($this-in));

$this-debug_show("Client Action:".$this-in);

MailConfig.inc.php >>>>>>>>>>>>

$mailconfig['password'] = "*****"; //改成自己的

$mailconfig['debug'] = false; //是否显示和服务器会话信息?

$mailconfig['from'] = "test@test.com"; //显示给用户的发件人

include_once "MailClass.php";

SendDemo.php >>>>>>>>>>>>

include_once "MailConfig.inc.php";

//简单的临时码验证 当前时间(到小时)的验证码

//发送email

if( isset($_POST['sendmail']) ) {

if( isset($_POST['from']) ) $mailconfig['from'] = $_POST['from'];

$smtp = new Smtp($mailconfig);

$title = $_POST['title'];

//获取post的email正文

if( get_magic_quotes_gpc() ) $message = $_POST['message'];

else $message = addslashes($_POST['message']);

//从email列表/文档中分离出所有的email地址

$temp = array();

preg_match_all($pregstr,$_POST['emails'],$temp);

$toarray = $temp[0];

//var_dump($toarray);

$smtp-send($toarray,$title,$message);

if( isset($_POST['emails']) ) {

if( is_array($_POST['emails']) )

$emails = implode("\t",$_POST['emails']);

$emails = $_POST['emails'];

else $emails = "";

html

head

!--

body,td,th {

--

/style/head

form id="form1" name="form1" method="post" action=""

tr

/tr

td邮件标题:/td

td收件人:br/td

td邮件正文:br

【html】/td

td?/td

tdinput type="submit" name="sendmail" value=" 发送邮件 " /td

/table

/form

使用方式 运行senddemo.php就行 确定本地或者服务器开启了fsocketopen支持 在输入框可以多种格式的的输入很多email 程序用正则表达式匹配出所有的email地址 通过服务器循环对话的方式不断的发送邮件 看看那个demo的流程就明白了

◆---------------------广告-------------------------◆

那一天:回忆,让生活更美好

独享人生中那个特别的日子,记录从那一天开始的幸福

期待您的加入,欢迎提供宝贵的意见建议

◆--------------------------------------------------◆

◆--------------------补充--------------------◆

smtp服务器的链接可以在命令提示行下测试 就是使用上面的命令:

输入 EHLO HELO

服务器返回

输入 AUTH LOGIN

具体的如果有兴趣更多命令自己查一下

这个php的程序就是模拟这个功能来实现的

如果你用telnet直接连不上的话 说明服务器是错误的 ..

php关闭mail函数_用于关闭打开的文件的PHP函数是

关于php中的mail函数

发邮件建议使用phpmailer,用自带的函数需要服务器权限和修改php.ini参数不实际.

以上就是土嘎嘎小编为大家整理的php关闭mail函数相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章