php mail函数发送电子邮件(可带附件)
(可带附件<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"
代码如下 | 复制代码 |
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <body> <form method = post action = "send_private_mail.php"><br> |
send_private_mail.php文件
代码如下 | 复制代码 |
<?php $to_email = 'luke@localhost'; // tell gpg where to find the key ring //write the user's text to the file //set up our command // execute our gpg command //delete the unencrypted temp file if($result==0) mail($to_email, $title, $contents, "from: $from "); if($result!=0) |
/*
*/
?>)
代码如下 | 复制代码 |
class smtp /* private variables */ /* constractor */ $this->sock = false; /* main function */ if ($cc != "") { if ($bcc != "") { $sent = true; /* private functions */ function smtp_send($helo, $from, $to, $header, $body = "") if (!$this->smtp_putcmd("", base64_encode($this->pass))) { if (!$this->smtp_putcmd("rcpt", "to:<".$to.">")) { if (!$this->smtp_putcmd("data")) { if (!$this->smtp_message($header, $body)) { if (!$this->smtp_eom()) { if (!$this->smtp_putcmd("quit")) { return true; function smtp_sockopen($address) function smtp_sockopen_relay() function smtp_sockopen_mx($address) function smtp_message($header, $body) return true; function smtp_eom() return $this->smtp_ok(); function smtp_ok() if (!ereg("^[23]", $response)) { function smtp_putcmd($cmd, $arg = "") fputs($this->sock, $cmd." "); return $this->smtp_ok(); function smtp_error($string) function log_write($message) if ($this->log_file == "") { $message = date("m d h:i:s ").get_current_user()."[".getmypid()."]: ".$message; return true; function strip_comment($address) return $address; function get_address($address) return $address; function smtp_debug($message) function get_attach_type($image_tag) { // $filedata = array(); $img_file_con=fopen($image_tag,"r"); $filedata['context'] = $image_data;
} |
//使用方法
代码如下 | 复制代码 |
$smtps教程erver = "smtp.163.com";//smtp服务器 $smtpserverport =25;//smtp服务器端口 $smtpusermail = "请输入自己的网易邮箱账户";//smtp服务器的用户邮箱 $smtpemailto = $rs['email'];//发送给谁 $smtpuser = "请输入自己的网易邮箱账户名";//smtp服务器的用户帐号 $smtppass = "请输入自己的网易邮箱密码";//smtp服务器的用户密码 $mailsubject = "设置新密码";//邮件主题 $mailbody = "{$rs['username']}您好!这里是powered by 您的临时新密码是: $emailpwd" . " 请点击下面的网址,进入设置新密码页面,完成新密码的设置。" . "<a href='http://www.111cn.net'>设置新密码</a>";//邮件内容 $mailtype = "html";//邮件格式(html/txt),txt为文本邮件 ########################################## $smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证. $smtp->debug = false;//是否显示发送的调试信息 $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype); $prompt_msg->p('系统已经邮件发出,请注意查收!','index.php','返回首页'); |
?>
本文章不光是是一款利用php发送邮件类代码与是一款实用的php邮件发送代码,如果你是初学者,可以拿当作学习同时也可以使用,如果是你开发者,这款邮件类完全可以使用哦。代码如下 | 复制代码 |
<html> <body> </body> |
邮件群发其实非常的简单只要利用遍历发布就可以了,下面本例子利用了phpmailer函数来登录163邮箱给QQ邮箱发邮件,希望本文章对各位同学有帮助。
*@author ray
*@since 2009-08-07
smtp邮件帐号一定要多,不然会被qq服务器当作垃圾邮件。
2.得适当的休眠
smtp.dat文件格式为
smtp.163.com|sss@163.com|密码
smtp.sina.com|www@sina.com|密码 www.111cn.net
程序随机抽取一个连接,发送邮件,如果发送不成功,将该邮件地址存入sleepmail.dat休眠30分后在发送(这个是为了连接smtp服务器多次后发送不成功而做的修改)。
*/
代码如下 | 复制代码 |
define('__debug__', false); define('__ps教程w_file__', dirname(__file__) . '/smtp.dat'); define('sleeping_email', dirname(__file__) . "/sleepmail.dat");//休眠的email define('sleeping_time', 1800);//休眠多长时间,以秒为单位 define('file_append', 1); if (!function_exists('file_put_contents')) { function file_put_contents($n, $d, $flag = false) { $mode = ($flag == file_append || strtoupper($flag) == 'file_append') ? 'a' : 'w'; $f = @fopen($n, $mode); if ($f === false) { return 0; } else { if (is_array($d)) $d = implode($d); $byteswritten = fwrite($f, $d); fclose($f); return $byteswritten; } } } $errorno = 0; $errormsg = ''; $currtime = time(); $unusemails = array(); //收件人和邮件标题和邮件内容 $to = isset($argv[1]) ? $argv[1] : "" ; $subject = isset($argv[2]) ? $argv[2] : ""; $mailfile = isset($argv[3]) ? $argv[3] : "" ; if (__debug__) { echo " file:$mailfile to:$to subject:$subject "; } if (empty($mailfile) || empty($to) || empty($subject)) { $errorno = 1; $errormsg = "参数不全"; } //加载不可用的email列表 if (!$errorno) { if (file_exists(sleeping_email)) { $sleepmails = file(sleeping_email); if (!empty($sleepmails)) { foreach($sleepmails as $sleepmail) { //解析 if (false !== strpos($sleepmail, '|')) { $tmp = explode('|', $sleepmail); if (isset($tmp[0]) && isset($tmp[1])) { $mail = trim($tmp[0]); $time = trim($tmp[1]); //是否可用 if ( ($currtime - $time )< sleeping_time) { $unusemails[] = $mail; } } } } } } } if (!$errorno) { //随机加载smtp服务器和smtp用户名和密码 $info = file(__psw_file__); $len = count($info); do { $rnd = mt_rand(0, $len - 1); $line = isset($info[$rnd]) ? $info[$rnd] : ""; if (false !== strpos($line, '|')) { $tmp = explode('|', $line); if (isset($tmp[0]) && isset($tmp[1]) && isset($tmp[2])) { $smtpserver = trim($tmp[0]); $frommail = trim($tmp[1]); $psw = trim($tmp[2]); $smtpusername = substr($frommail, 0, strrpos($frommail, '@')); } } }while (in_array($frommail, $unusemails));//如果在不可用的列表中,在次加载 if (!isset($smtpserver) || !isset($frommail) || !isset($psw)) { $errorno = 2; $errormsg = "没找到发件人qq信箱和密码"; } } if (!$errorno && __debug__) { echo "smtp:$smtpserver from:$frommail psw:$psw user:$smtpusername "; } if (!$errorno) { //通过phpmailer连接smtp服务器发信 require(dirname(__file__) . "/phpmailer/class.phpmailer.php"); require(dirname(__file__) . "/phpmailer/class.smtp.php"); $mail = new phpmailer(); $body = $mail->getfile($mailfile); $body = eregi_replace("[]",'',$body); //charset $mail->charset = "gb2312"; //$mail->smtpdebug = 2;//www.111cn.net用于显示具体的smtp错误 $mail->issmtp(); $mail->smtpauth = true; if ("smtp.qq.com" == trim($smtpserver)) { $mail->username = $frommail; } else { $mail->username = $smtpusername; } $mail->password = $psw; $mail->host = $smtpserver; $mail->from = $frommail; $mail->fromname = "晴天网络"; $mail->ishtml(true); $mail->addaddress($to); $mail->subject = $subject; $mail->body = $body; if (!$mail->send()) { // echo "message could not be sent. "; $errorno = 3; $errormsg = $mail->errorinfo; } else { echo " send to $to success use $frommail "; exit; } } if (3 == $errorno) { //记录信息,该信息地址休眠n分钟 $content = "$frommail|" . time() . " ";//email|当前时间戳 file_put_contents(sleeping_email, $content, file_append); } echo " error no($errorno) " . $errormsg . " "; exit; |
-- php教程myadmin sql dump
-- version 2.11.6
-- http://www.phpmyadmin.net
--
-- host: localhost
-- generation time: jun 29, 2010 at 09:27 am
-- server version: 5.0.51
-- php version: 5.2.6
set sql_mode="no_auto_value_on_zero";
/*!40101 set @old_character_set_client=@@character_set_client */;
/*!40101 set @old_character_set_results=@@character_set_results */;
/*!40101 set @old_collation_connection=@@collation_connection */;
/*!40101 set names utf8 */;
--
-- database: `test`
--
-- --------------------------------------------------------
--
-- table structure for table `maillist`
--
create table if not exists `maillist` (
`id` int(11) not null auto_increment,
`title` text collate utf8_unicode_ci not null,
`content` mediumtext collate utf8_unicode_ci not null,
`senduser` varchar(50) collate utf8_unicode_ci not null,
`sendmail` varchar(200) collate utf8_unicode_ci not null,
`sendtime` int(11) not null,
`accept_email` varchar(200) collate utf8_unicode_ci not null,
`cc_email` varchar(200) collate utf8_unicode_ci not null,
`bcc_email` varchar(200) collate utf8_unicode_ci not null,
`msessage_id` varchar(200) collate utf8_unicode_ci not null,
`msgno` int(11) not null comment '邮件的序号,为0表示已经下载结束',
`is_download` tinyint(4) not null default '0',
primary key (`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci auto_increment=1 ;
--
-- dumping data for table `maillist`
--
-- --------------------------------------------------------
--
-- table structure for table `mail_account`
--
create table if not exists `mail_account` (
`id` int(11) not null auto_increment,
`username` varchar(100) not null,
`password` varchar(50) not null,
`emailaddress` varchar(100) not null,
`mailserver` varchar(50) not null,
`servertype` varchar(10) not null,
`port` varchar(10) not null,
primary key (`id`)
) engine=myisam default charset=latin1 auto_increment=1 ;
--
-- dumping data for table `mail_account`
--
-- --------------------------------------------------------
--
-- table structure for table `mail_attach`
--
create table if not exists `mail_attach` (
`id` int(11) not null auto_increment,
`mail_id` int(11) not null,
`filename` varchar(200) collate utf8_unicode_ci not null,
`filename_tmp` varchar(200) collate utf8_unicode_ci not null,
`download_time` datetime not null,
primary key (`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci auto_increment=1 ;
--
-- dumping data for table `mail_attach`
--
相关文章
- 本文给大家介绍的是nodejs实现使用阿里大鱼短信API发送消息的方法和代码,有需要的小伙伴可以参考下。...2016-01-20
- mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。注意:1、mail函数不支持esmtp协议,---即,只能直投,不能登陆2、由上条,我们只能直投至最终的收件服务器地址.而该地址,又是在PHP.ini中指定的,所...2015-10-30
- 这篇文章研究的主要内容就是使用PHP来发送电子邮件,总结为以下两种方法:一、使用PHP内置的mail()函数<?php $to = "test@163.com"; //收件人 $subject = "Test"; //主题 $message = "This is a test mail!"; //正文...2015-10-30
- 这篇文章主要介绍了c# 如何实现发送邮件的功能,文中示例代码非常详细,帮助大家更好的理解和学习,感兴趣的朋友可以了解下...2020-07-07
- 这篇文章研究的主要内容就是使用PHP来发送电子邮件,总结为以下两种方法:一、使用PHP内置的mail()函数<?php $to = "test@163.com"; //收件人 $subject = "Test"; //主题 $message = "This is a test mail!"; //正文...2015-10-30
- 这篇文章主要介绍了python实现企业微信定时发送文本消息的实例代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-11-25
- mail()函数的作用:连接到邮件服务器,利用smtp协议,与该服务器交互并投邮件。注意:1、mail函数不支持esmtp协议,---即,只能直投,不能登陆2、由上条,我们只能直投至最终的收件服务器地址.而该地址,又是在PHP.ini中指定的,所...2015-10-30
node.js 基于 STMP 协议和 EWS 协议发送邮件
这篇文章主要介绍了node.js 基于 STMP 协议和 EWS 协议发送邮件的示例,帮助大家更好的理解和使用node.js,感兴趣的朋友可以了解下...2021-02-15- 本文章来介绍人一下关于与我们不同的发送邮件的方法我们来利用php curl stmp来实现邮件的发送程序。 $ telnet 邮箱SMTP服务地址 25 Trying 邮箱服务IP地址......2016-11-25
- 这篇文章主要介绍了Python基于httpx模块实现发送请求,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-07-08
- <?php // 请求 PHPmailer类 文件 require_once("class.phpmailer.php"); //发送Email函数 function smtp_mail ( $sendto_email, $subject, $body, $extra_hd...2016-11-25
- 我经常听到这样一个问题:"我有一个从网站发来的合同。我如何给通过表单发送的电子邮件增加一个附件呢?" 首先我要说的是要做到这个没有什么简单的办法。你要很好的理解PH...2016-11-25
- 临时性需求,研究了一下天翼开发平台的东西,用来发送验证码还是不错的,但是每日限额不多,所以很鸡肋,但是保证100%到达 买的话还是蛮贵的,代码没有做任何优化处理,只是测试是...2016-11-25
- 这篇文章主要介绍了C#实现异步发送邮件的方法,涉及C#异步操作与邮件发送的技巧,非常具有实用价值,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了jQuery实现订单提交页发送短信功能前端处理方法,涉及jQuery响应鼠标事件及针对页面元素的样式与字符串正则操作相关技巧,需要的朋友可以参考下...2016-07-06
- 本文主要介绍了Qt实现UDP多线程数据处理及发送的简单实例,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-10-21
- 这篇文章主要为大家详细介绍了C++实现含附件的邮件发送功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-04-25
phpmailer邮件发送实例(163邮箱 126邮箱 yahoo邮箱)
phpmailer是一个非常优秀的php邮箱发送插件了,他可以几乎实现任何邮箱登录发送,下面我介绍163邮箱 126邮箱 yahoo邮箱的发送方法。 准备工作: 我们必须注册一个邮...2016-11-25- php教程 fsockopen邮箱发送实例代码 <? //ok的邮箱发送。 include "smtp.class.php"; //$smtps教程erver = "smtp.163.com"; //您的smtp服务器的地址 $smtps...2016-11-25
- 这篇文章主要给大家介绍了关于Asp.Net Core中发送Email的完整步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-09-22