分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

phpmailer 发送图片

发布时间:2023-09-06 01:50责任编辑:熊小新关键词:暂无标签
 

php对邮箱地址进行检测

 1 function PageIsMail(array $email_arr){ 2 ????foreach($email_arr as $email) { 3 ????????//邮箱正则匹配(不能以-_.开头) 4 ????????if (!preg_match("/^[0-9A-Za-z][0-9A-Za-z-_.]*@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i", $email)){ 5 ????????????echo "(method1)invalid email: $email<br />"; 6 ????????????continue; 7 ????????} 8 ????????//名称在4到16位之间 9 ????????if (strlen(explode("@",$email)[0])<4 or strlen(explode("@",$email)[0])>16 ){10 ????????????echo "(method2)invalid email: $email<br />";11 ????????????continue;12 ????????}13 ????????//域名是否存在(依赖网络,不建议使用)14 ????????if(checkdnsrr(explode("@",$email)[1],"MX") === false) {15 ????????????echo "(methodof3)invalid email: $email<br />";16 ????????????continue;17 ????????}18 ????????echo "email: $email<br />";19 ????}20 }

phpmailer 发送带图片的邮件

直接上代码

 1 // 发送邮件 2 function SendMail(){ 3 ????require_once("./msg/class.phpmailer.php"); 4 ????$mail = new PHPMailer(); 5 ????//$mail->SMTPDebug = 3; 6 ????$this->mail=$mail; 7 ????$this->mail->isSMTP(); 8 ????$this->mail->CharSet = ‘UTF-8‘; 9 ????$this->mail->Host = ‘smtp.exmail.qq.com‘;10 ????$this->mail->SMTPAuth = true;11 ????$mail->Username = ‘xxx@xx.com‘;12 ????$mail->Password = ‘pwd‘;13 ????$this->mail->SMTPSecure = ‘ssl‘;14 ????$this->mail->Port = 465;15 ????$this->mail->From = ‘xxx@xx.com‘;16 ????$this->mail->addAddress(‘yyy@yy.com‘,‘toName‘);17 ????$this->mail->isHTML(true);18 ????$this->mail->Subject = ‘中文主题测试‘;19 ????$hmtl = ‘<i>帅哥</i>:<b>你好</b>!!!<br><img src="./static/pic/xx.png" /><br><img src="./static/pic/xx.png" />‘;20 ????//带图处理,不带图不处理,图片格式如上(图片未加格式)21 ????$this->mail->Body = ProcessImg($hmtl);22 ????$this->mail->AltBody = strip_tags($hmtl);23 ????if(!$this->mail->send()) {24 ????????echo ‘Message could not be sent.‘;25 ????????echo ‘Mailer Error: ‘ . $this->mail->ErrorInfo;26 ????} else {27 ????????echo ‘Message has been sent‘;28 ????}29 }30 31 // 处理MailBody中的图片,将本地图片加入附件方可发送成功32 function ProcessImg($html){33 ????$resutl = preg_match_all(‘@<img src=.+? />@‘, $html, $matches);34 ????if(!$resutl) return $html;35 ????$trans = array();36 ????foreach ($matches[0] as $key => $img) {37 ????????$id = ‘img‘ . $key;38 ????????preg_match(‘/src="(.*?)"/‘, $html, $path);39 ????????if ($path[1]){40 ????????????$this->mail->addEmbeddedImage($path[1], $id);41 ????????????$trans[$img] = ‘<img src="cid:‘ . $id . ‘" />‘;42 ????????}43 ????}44 ????$html = strtr($html, $trans);45 ????return $html;46 }

  

phpmailer 发送图片

原文地址:https://www.cnblogs.com/elephanyu/p/8908755.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved