function send_check_mail($email, $subject,$uid,$buffer)
{
echo "hello";
$command = "/var/qmail/bin/qmail-inject ".$email; //qmail程序地址,$email是要发送的地址
$handle = popen($command, "w"); //打开管道
if (!$handle) {
return false;
}$from = "yangxuemei2012@111cn.net"; //发件人
fwrite($handle, "from: ".$from."n"); //往管道写数据
fwrite($handle, "return-path: ".$from."n");
fwrite($handle, "to: ".$uid."n");
fwrite($handle, "subject: ".$subject."n");
fwrite($handle, "mime-version: 1.0n");
fwrite($handle, "content-type: text/html; charset="gb2312"nn");
fwrite($handle, $buffer."n");
pclose($handle); //关闭管道return true;
}
$subject = "测试邮件";$uid = $_post['uid']; //from信息
$content= "<html><body>".$u_email." 您好!<br><br>谢谢,www.111cn.net!<br</body></html>"; //内容信息
$u_email = "machunjie2003@111cn.net"; //发送到的邮箱
if (send_check_mail($u_email, $subject, $uid, $content)) {echo "恭喜!发送投票邮件到您的邮箱!<br><br>请检查您的邮箱:<font color=#cc0033>".$u_email." </font><br><br>". $close;
} else {echo "很不幸,发送投票邮件到您的邮箱失败,请重试或者联系开发人员。<br><br>". $close;
}
不需要邮件服务器,不使用mail内置函数,一个类就搞定,利用php教程mailer类我写了一个自定义函数 sendmail() ,very实用!
以前也在几个php论坛上发表过这个发邮件的函数,今天再发,因为today要附上使用例子,如果你还不会用,那就要补补php基础课了。
1.准备文件 sendmail.class.php文件、phpmailer类 下载
2.下载后,解压 phpmailer.rar 到服务器的任何目录下
3.打开 sendmail.class.php ,修改如下(浅黄色部分是必须 要修改的变量值)
// 以下 5 个变量值必须据实修改
$host = '61.183.41.172';
$username = 'admin@php95.com';
$password = "******"
$from = 'admin@php95.com';
$fromname = '天马博客';
// 先设置 $to $subject $content 这三个变量的值,再调用 sendmail 函数来发送邮件
$to = 'nt2030@qq.com';
$subject = '测试phpmailer类发送邮件';
$content = '测试phpmailer类发送邮件';
sendmail($to,$subject,$content);
4.修改 sendmail.class.php 完毕后,运行它..
你的邮件是否发送成功?
天马测试本代码,is ok,见证:
代码如下 | 复制代码 |
$pdfname="test.pdf"; $text = base64_encode($text); //用base64方法把它编码 $subject = $pdfname; //标题 //附件 $read=file_get_contents($pdfname); $read = base64_encode($read); //用base64方法把它编码 //现在我们可以建立邮件的主体 ------=_$boundary ------=_$boundary2 $text ------=_$boundary2-- ------=_$boundary $read -------=_$boundary--"; if(mail($to, $subject,$body,$headers)) |
?>
用的mail()函数,感觉不好用,而且感觉这个邮件地址不能太多,一次copy了100个可能会出问题,下面提供一款可以限制发送邮件php类函数。
*/
代码如下 | 复制代码 |
class sendmail{ function set($server=yj_sysmail_smtp,$user="",$password=yj_sysmail_pass,$port=yj_sysmailport,$type=1,$mailusername=0){ $this->type = $type; function send($email_to, $email_subject, $email_message, $email_from = ''){ if($this->type == 1){ function smtp($email_to, $email_subject, $email_message, $email_from = '', $headers = ''){ function errorlog($type, $message, $is){ function mailmess($mess=""){ |
本款php发送邮件代码他利用了php自由的邮件发送函数mail进行邮件发送的,他会利用二种试一是判断mail函数是否可用,如果行就利用它来发送否则fsockopen来操作。
*/
代码如下 | 复制代码 |
class email function __construct() function set($server, $port, $user, $password, $type = 1, $delimiter = 1, $mailusername = 0) function smtp($email_to, $email_subject, $email_message, $email_from = '', $headers = '') function errorlog($type, $message, $is) |