php发送邮件

如何解决ORA-29279: SMTP permanent error: 504 5.7.4 Unrecognized authentication type错误 某些功能自动发邮件给用户,之前一直使用好好的。突然收到运维人员或用户反馈,无法发送邮件。提示错误:ORA-29279: SMTP permanent error: 504 5.7.4 Unrecognized authentication type 阅读详情

新建文件 smtp.clss.php  里面代码不用修改!

代码如下:

<?php
class smtp_class{
 
 
 var $Priority   = 3;
 var $CharSet   = "iso-8859-1";
 var $ContentType  = "text/plain";
 var $Encoding   = "8bit";
 var $FromEmail   = "root@localhost";
 var $FromName   = "root";
 var $Subject   = "";
 var $Body    = "";
 var $WordWrap   = "";
 var $MailerDebug  = false;
 var $UseMSMailHeaders = true;
 var $IsHTML    = false;
 var $IPAddress   = "unknown";
 var $Timezone   = "+0000";
 
 
 
 var $Host    = "localhost";
 var $Port    = 25;
 var $Timeout   = 10;
 var $Helo    = "";
 
 
 
 var $Version   = "";
 var $To     = array();
 var $Cc     = array();
 var $Bcc    = array();
 var $ReplyTo   = array();
 var $Attachment   = array();
 var $CustomHeader  = array();
 var $boundary   = "";
 var $ErrorAlerts  = array();
 var $AuthLogin   = false;
 var $AuthUser   = "";
 var $AuthPass   = "";
 var $CRLF    = "\r\n";
 var $error_status  = false;
 var $current_count  = 0;
 
 
 function From($address,$name){
  $this->FromEmail=trim($address);
  if($name==""){
   $this->FromName=$this->FromEmail;
  }else{
   $this->FromName=$name;
  }
 }
 
 
 function AddTo($address,$name){
  $current_count=count($this->To);
  $this->To[$current_count][0]=trim($address);
  $this->To[$current_count][1]=$name;
 }
 
 
 function AddCc($address,$name){
  $current_count=count($this->Cc);
  $this->Cc[$current_count][0]=trim($address);
  $this->Cc[$current_count][1]=$name;
 }
 
 
 function AddBcc($address,$name){
  $current_count=count($this->Bcc);
  $this->Bcc[$current_count][0]=trim($address);
  $this->Bcc[$current_count][1]=$name;
 }
 
 
 function AddReplyTo($address,$name){
  $current_count=count($this->ReplyTo);
  $this->ReplyTo[$current_count][0]=trim($address);
  $this->ReplyTo[$current_count][1]=$name;
 }
 
 
 function AddAttachment($path,$name,$type="application/octet-stream"){
  if($name==""){
   $name=basename($path);
  }
  
  $current_count=count($this->Attachment);
  $this->Attachment[$current_count][0]=$path;
  $this->Attachment[$current_count][1]=$name;
  $this->Attachment[$current_count][2]=$type;
 }
 
 
 function SMTP_open($host,$port,$timeout){
  $this->smtp_connection=fsockopen($host,$port,$errno,$errstr,$timeout);
  if(empty($this->smtp_connection)){
   return false;
  }
 
  $this->get_lines();
  return true;
 }
 
 
 function SMTP_close(){
  fclose($this->smtp_connection);
  return true;
 }
 
 
 function Send(){
  
  # open SMTP connection
  if(!$this->SMTP_open($this->Host,$this->Port,$this->Timeout)){
   $this->error_handler("SMTP Error: SMTP Connection Fail.");
   return false;
  }
  
  # if SMTP need authorization
  if($this->AuthLogin==true){
   
   # send the EHLO command to SMTP
   $this->send_lines("EHLO ".$this->Host);
   if(substr($this->get_lines(),0,3)!=250){
    $this->error_handler("SMTP Error: EHLO not accepted from server.");
   }
   
   # send AUTH LOGIN command
   if($this->error_status==false){
    $this->send_lines("AUTH LOGIN");
    if(substr($this->get_lines(),0,3)!=334){
     $this->error_handler("SMTP Error: AUTH LOGIN not accepted from server.");
    }
   }
   
   # username and password authorization
   if($this->error_status==false){
    $this->SMTP_Auth();
    if(substr($this->get_lines(),0,3)!=235){
     $this->error_handler("SMTP Error: Authentication failed.");
    }
   }
   
  }else{
   
   # send the HELO command to SMTP
   $this->send_lines("HELO ".$this->Host);
   if(substr($this->get_lines(),0,3)!=250){
    $this->error_handler("SMTP Error: HELO not accepted from server.");
   }
   
  }
  
  
  # define sender email
  if($this->error_status==false){
   $this->send_lines("MAIL FROM: ".$this->FromEmail);
   if(substr($this->get_lines(),0,3)!=250){
    $this->error_handler("SMTP Error: MAIL not accepted from server.");
   }
  }
  
  
  # define sending email address
  $this->reset_current_count();
  while($this->error_status==false and $this->current_count<count($this->To)){
   
   $this->SMTP_RCPT($this->To[$this->current_count][0]);
   $this->current_count++;
   
  }
  $this->reset_current_count();
  while($this->error_status==false and $this->current_count<count($this->Cc)){
   
   $this->SMTP_RCPT($this->Cc[$this->current_count][0]);
   $this->current_count++;
   
  }
  $this->reset_current_count();
  while($this->error_status==false and $this->current_count<count($this->Bcc)){
   
   $this->SMTP_RCPT($this->Bcc[$this->current_count][0]);
   $this->current_count++;
   
  }
  
  
  # send mail
  $this->SMTP_Data("");
  
  
  # close SMTP connection
  $this->SMTP_close();
  
  
  # return send email success or fail
  if($this->error_status){
   return false;
  }else{
   return true;
  }
 }
 
 
 function reset_current_count(){
  $this->current_count=0;
 }
 
 
 function SMTP_RCPT($emailto){
  # send the RCPT TO command to SMTP
  $this->send_lines("RCPT TO: ".$emailto);
  if(substr($this->get_lines(),0,3)!=250){
   $this->error_handler("SMTP Error: RCPT TO not accepted from server.");
  }
 }
 
 
 function SMTP_Auth(){
  $this->send_lines(base64_encode($this->AuthUser));
  $this->get_lines();
  $this->send_lines(base64_encode($this->AuthPass));
 }
 
 
 function SMTP_Data($message){
  # send the DATA command to SMTP
  if($this->error_status==false){
   $this->send_lines("DATA");
   if(substr($this->get_lines(),0,3)!=354){
    $this->error_handler("SMTP Error: DATA not accepted from server.");
   }
  }
  
  if($this->error_status==false){
   $this->boundary="_alangor" . md5(uniqid(time()));
   
   # send header
   $this->Create_Header();
   
   # send body
   if(count($this->Attachment)>0){
    $this->send_lines("----=".$this->boundary);
    $this->send_lines("Content-Type: ".$this->IsHTML($this->IsHTML)."; charset=\"".$this->CharSet."\";");
    $this->send_lines("");
   }
   $this->Create_Body();
   $this->send_lines("");
   
   # add attachment
   if(count($this->Attachment)>0){
    $this->append_attachment();
   }
   
   # end of message
   $this->send_lines(".");
  }
  
  
 }
 
 
 function Create_Header(){
  $this->send_lines("Received: from client ".getenv("REMOTE_ADDR")." for alangor.com development team; ".date("D, j M Y G:i:s")." ".$this->Timezone);
  $this->send_lines("Date: ".date("D, j M Y G:i:s")." ".$this->Timezone);
  $this->send_lines("From: \"".$this->FromName."\" <".$this->FromEmail.">");
  if(count($this->To)>0){
   $this->send_lines($this->append_email("To",$this->To));
  }
  if(count($this->Cc)>0){
   $this->send_lines($this->append_email("Cc",$this->Cc));
  }
  if(count($this->ReplyTo)>0){
   $this->send_lines($this->append_email("Reply-to",$this->ReplyTo));
  }
  $this->send_lines("Subject: ".$this->Subject);
  $this->send_lines("X-Priority: ".$this->Priority);
  $this->send_lines("X-Mailer: ".$this->Version);
  $this->send_lines("X-Original-IP: ".getenv("REMOTE_ADDR"));
  $this->send_lines("Content-Transfer-Encoding: ".$this->Encoding);
  $this->send_lines("Return-Path: ".$this->FromEmail);
  $this->send_lines("MIME-Version: 1.0");
  if(count($this->Attachment)>0){
   $this->send_lines("Content-Type: multipart/mixed; charset=\"".$this->CharSet."\";");
   $this->send_lines("\tboundary=\"--=".$this->boundary."\"");
  }else{
   $this->send_lines("Content-Type: ".$this->IsHTML($this->IsHTML)."; charset=\"".$this->CharSet."\";");
  }
  $this->send_lines("");
 }
 
 
 function Create_Body(){
  if($this->WordWrap){
   $this->Body=wordwrap($this->Body,$this->WordWrap,"\n",1);
  }
  $this->send_lines(ereg_replace("\n","\r\n",$this->Body));
 }
 
 
 function append_email($type,$email) {
  $email_string=$type.": ";
  for($i=0;$i<count($email);$i++){
   if($i>0){
    $email_string.=",\r\n\t";
   }
   if(trim($email[$i][1])!= ""){
    $email_string.="\"".$email[$i][1]."\" <".$email[$i][0].">";
   }else{
    $email_string.="\"".$email[$i][1]."\"";
   }
  }
  return($email_string);
 }
 
 
 function append_attachment(){
  for($i=0;$i<count($this->Attachment);$i++){
   $this->send_lines("----=".$this->boundary);
   $this->send_lines("Content-Type: ".$this->Attachment[$i][2]."; name=\"".$this->Attachment[$i][1]."\"");
   $this->send_lines("Content-Transfer-Encoding: base64");
   $this->send_lines("Content-Disposition: attachment; filename=\"".$this->Attachment[$i][1]."\"\r\n");
   $this->send_lines(chunk_split(base64_encode(implode(file($this->Attachment[$i][0]))))."\r\n");
  }
 }
 
 function IsHTML($status){
  if($status==true){
   return $this->ContentType="text/html";
  }else{
   return $this->ContentType="text/plain";
  }
 }
 
 
 function error_handler($message){
  if($this->MailerDebug==true){
   echo $message;
  }
  if($message!=""){
   return $this->error_status=true;
  }else{
   return $this->error_status=false;
  }
 }
 
 
 function get_lines(){
  while($data=fgets($this->smtp_connection,1024)){
   if(substr($data,3,1)==" "){
    break;
   }
  }
  return $data;
 }
 
 
 function send_lines($command){
  fputs($this->smtp_connection,$command."\r\n");
 }
 
}

?>

 

下面是一个测试文件:

<?php
require_once('smtp.class.php');
$mail=new smtp_class;
$mail->Host            = "smtp.qq.com";  // SMTP server. like smtp.21cn.com
$mail->Port            = 25;  // SMTP port. Default: 25;
$mail->Timeout        = 10;  // SMTP connection timeout. Default: 10;
$mail->Timezone        = "+0800";  // Time Zone. Default: "+0000";
$mail->Priority        = 3;  // Email priority Default: 3 (1=High,3=Medium or 5=Low);
$mail->CharSet        = "UTF-8";  // Character set.
$mail->WordWrap        = 0;  // characters per line. 0 for umlimit characterc per line
$mail->IsHTML        = true;  // HTML email. Default: false (true or false);
$mail->MailerDebug    = true;  // Display SMTP error. Default: false (true or false);
$mail->AuthLogin    = true;  // using SMTP authorization. Default: false (true or false);
$mail->AuthUser        = "账号";  // SMTP username  我用qq邮箱测试通过(到qq邮箱开通smtp服务)
$mail->AuthPass        = "密码";  // SMTP password  邮箱登陆密码

# email address and content start here
$mail->From("发送邮箱地址","WebDNA");   最好和上面的账号一直
$mail->AddTo("接受邮件地址","guest name");
$mail->Subject="E-mail to website";
$mail->Body="测试邮件";   //这里就是你要发的内容
if(!$mail->Send()){ 
     echo "发送失败";
}else{ 
     echo "发送成功";}
?>

 

【鸿蒙游戏上架审核规范指南】 华为鸿蒙游戏上架审核规范指南摘要 阅读详情

相关推荐

VMware桥接模式实战:用手机热点给Linux虚拟机共享网络(附WiFi适配技巧)

本文详细介绍了在移动办公场景下,如何为VMware中的Linux虚拟机配置桥接模式,以通过手机热点共享网络。文章深入解析了桥接模式在无线环境下的工作原理,提供了从主机端准备、VMware设置到Linux虚拟机内部配置的完整实战步骤,并针对手机热点的特殊性,分享了MTU优化、DNS配置及常见网络问题的诊断与解决方案,帮助用户实现稳定高效的移动虚拟化办公。

2y3u4i5o6p的博客 1217

PHP 发送邮件SMTP Error: Could not authenticate

1.查看对应的发送账号和密码是否正确2.查看代码是否有出错信息3.查看邮箱是否开启smtp服务以上排查都不是,然后自己登录网页手动发送邮件,发现提示是被投诉了,邮件暂时不能发送,然后联系客服解除,重新设置密码后在客户端那边重新生成新的授权码,替换smtp的密码后就可以发送成功了,解决思路,先要排查发送的邮箱是否可以正常接受邮件,再查看是否开启smtp

ahjxhy2010的博客 2839

Cube.js 安装避坑指南:从零到一键启动

本文是一份详细的Cube.js安装避坑指南,旨在帮助开发者从零开始顺利启动Cube.js。文章重点强调了安装前的环境准备,包括Node.js版本、包管理工具和项目路径等关键“地基”,并深入解析了使用npx安装的优势、数据库类型选择以及数据库连接配置的核心步骤与常见陷阱,确保您能高效完成安装并成功启动服务。

weixin_29218509的博客 434

opencart配置mail服务

编辑mail配置,如下图所示 如果sever开启了SSL,则端口改成465 在Contant Us页面留言,发送成功则配置完成 Error: RCPT TO not accepted from server”,该问题一般是因为邮件服务器不支持自己发邮件到自己邮箱,解决方法,程序里自定义设置目标邮箱地址1.联系我们contactcatalog/controller/information/...

weixin_33939843的博客 519

LTO编译器优化介绍以及开启方法

LTO优化的详细介绍

性感的小君君 4936

手把手教你用SlowFast训练自定义手势识别数据集(附FFmpeg抽帧技巧)

本文提供了一份基于SlowFast架构训练自定义手势识别数据集的完整实战指南。文章重点剖析了数据准备的核心挑战,详细讲解了利用FFmpeg进行高、低帧率抽帧的技巧,并介绍了构建半自动标注流水线、生成符合SlowFast要求的AVA格式数据集文件的具体方法。最后,针对手势识别场景,给出了关键的模型训练配置与调优建议,帮助开发者高效完成从数据到模型的全流程。

s1t2u3的博客 914

phpmailer实现发送注册验证邮件

今天下午才弄好 步骤如下: 1、http://sourceforge.net/projects/phpmailer/ 下载phpmail的类文件 2、解压,将class.phpmailer.php和class.smtp.php 两个文件放到项目里 3、开始写代码啦!目标实现,邮件从admin@163.com 发送到admin@qq.com if (!defined( "PT_

queenkathy的博客 2795

DO-178C详解:机载软件开发、验证与适航标准指南

DO-178C将软件划分为五个等级(A到E),这些等级是基于失效状态对航空器安全的影响而定。

qq_41854911的博客 2862

web hosting上opencart发送邮件问题解决方法

按照网上的方法,一直去尝试解决 opencart 2.0 出现的 “Error: EHLO not accepted from server” 问题,但是一直都没有成功。后来翻墙google在一个英文网站上找到了答案: “This topic is just for the purpose of sharing information on one of the problem spots in

xinghun_4的专栏 6815

YOLO-World:从入门到实战的多模态目标检测全指南

想象一下,你给模型一张“公园”的图片,再输入文字“红色的郁金香”,它能直接在图中框出所有红色郁金香的位置——这就是多模态目标检测:结合图像视觉信息和文本语义信息,同时完成“是什么”(分类)和“在哪里”(定位)的任务。传统目标检测(如YOLOv5、YOLOv8)只能识别预定义的类别(比如训练时学过“猫”“狗”),但多模态目标检测摆脱了“类别预定义”的限制,只要文本能描述,它就能检测,这就是“开放词汇检测(Open-Vocabulary Detection)”的魅力。

know_F0727的博客 208

【AI智能体】AI 编程 + 飞书CLI + Skills 重塑开发新范式实战操作详解

AI 编程 + 飞书CLI + Skills 重塑开发新范式实战操作详解

congge 3676

PHP实现发送邮件

不同类型的邮箱发送邮件的方式也是不同的。 下面我们就先给大家举例介绍qq邮箱开启发送邮件服务的方法。 首先我们登录qq邮箱,打开设置,选择帐户。 然后在帐户下,找到如下所示的开启服务部分。 开启服务中,前两个选项均可实现邮件发送服务。点击开启,会出现验证提示。 确认验证,成功开启POP3/SMTP服务后,就会出现以下授权码。 那么此授权码就可以用于PHP实现邮件发送的开发方法中。 注: 每次开...

coco1118的博客 1万+

ArtMate —— 美术公开课智能体开发全记录

本文档详细描述了一款专为中小学美术公开课设计的智能教学助手的开发过程。该智能体融合了多模态感知、自然语言交互、风格迁移与智能评价等技术,旨在辅助教师开展生动、高效的美术鉴赏与创作课程。全文包含需求分析、系统架构设计、核心模块代码实现、交互界面搭建及完整运行示例,并配有详尽的行内注释和设计思想阐述,为教育技术开发者提供一份可落地、可扩展的参考方案。

huanghm88的专栏 157

PHP 发送邮件

本文章向大家介绍php中如何发送邮件。php发送邮件一般有两种方法,第一种方法是使用php内置函数mail(),第二种方法是使用第三方类库,比如PHPMailer,相比较而言,使用第三方类库更好,因为使用php mail()函数发送邮件有局限性。

wuxiaopengnihao1的博客 7119

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

PHP邮件发送空邮件

邮件发送空邮件大纲一、邮件发送的基本概念(一)邮件协议邮件协议是指用于在网络上发送和接收电子邮件的规则和标准。常见的邮件协议包括 SMTP(简单邮件传输协议)、POP3(邮局协议版本 3)和 IMAP(Internet 消息访问协议)。SMTP 用于发送邮件,POP3 和 IMAP 用于接收邮件。在 PHP 中,可以使用内...

880

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

PHP 发送电子邮件

PHP 允许您从脚本直接发送电子邮件。

m0_72763148的博客 1136

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

如何使用PHP进行邮件发送?

PHPMailer是一个强大的邮件发送类库,支持多种邮件发送方式(SMTP、sendmail、mail等),支持HTML邮件、附件、多收件人等功能。PHPMailer提供了丰富的功能和灵活的配置选项,可以满足各种复杂的邮件发送需求。在发送邮件时,需要注意服务器的邮件发送功能配置,以及邮件内容。函数依赖于服务器的邮件发送功能,如果服务器没有正确配置邮件发送服务,那么邮件可能无法成功发送。函数的功能相对简单,对于复杂的邮件发送需求(如HTML邮件、附件等),可能无法满足。对于简单的邮件发送需求,可以使用。

Layla_c的博客 5976

PHP 定时发送邮件

由于工作需要,做了一个PHP自动发送邮件的功能,为了以后可能需要,先简单记录一下 1. 下载专门为PHP发送邮件服务的包class.phpmailer,这个网上可以下载 2. 那么如何使用这个包发送邮件呢? 1. function emailgroup($From_u_name,$From_u_cname,$To_u_name,$To_u_cname,$dp_name,$gro

fangchongbory的专栏 6693

PHP发送邮件

发送邮件是网站的常用功能,用户激活、找回密码等场景常需要发送邮件到用户邮箱。本文先回顾发送邮件的相关概念,再给出使用PHP发送邮件的示例代码。 发送短信 从功能上看,短信和邮件类似,用途常是通知和安全校验。发送短信(基本上)需要向供应商付费,所以短信供应商有动力提供清晰的文档,易用的接口方便用户接入。一般而言,发送短信的是: 寻找供应商,例如阿里大鱼、聚合数据等; ...

谢谢你,慌乱了我的年华 1114

发送邮件php,发送邮件的PHP类

搜索热词下面是编程之家 jb51.cc 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。class emailui{static function runlog($mode = 'SMTP',$b = '',$c = '',$d='') {}static function sendmail($toemail,$subject,$message,$from='',$cfg ...

weixin_39937447的博客 329

php使用SMTP发送邮件

发送邮件代码部分: 记得引入email.class.php文件 <?php header("Content-Type: text/html; charset=utf-8"); require 'email.class.php'; $mailto='收件人邮箱地址'; //收件人 $subject="我是邮件主题"; //邮件主题 $body="...

weixin_42028285的博客 1263

PHP实战之发送邮件

#程序员薪资揭榜#你做程序员几年了?月薪多少?发量还在么?>>> ...

六道有言的博客 998

php发送邮件功能(以QQ邮件为例)

1. PHP开启Socket扩展 打开phpstudy,设置——>配置文件——>打开php.ini 打开进入php.ini文件,添加 extension=php_sockets.dll 然后phpinfo() 函数查看 socket 扩展信息 2. PHP开启openssl 扩展 同上,添加extension=php_openssl.dll 3. 生成QQ邮箱授权码 登录自...

linxinfa的专栏 4353

php发送邮件二种方法 php使用smtp发送邮件

原文:http://www.jbxue.com/php/25502.html 本文介绍了php发送邮件的两种方法,分别是使用PHP内置的mail()函数发送邮件,使用封装SMTP协议的邮件类发送邮件,推荐使用smtp协议封装的邮件类实现邮件发送。 php如何发送邮件呢?方法有很多,但用的最多的还是使用smtp协议来发送邮件,一起来学习下吧。 专题推荐:php发邮件代码大全 一、

lorielei的博客 3607

有关php邮件发送一点记录

php邮件发送需要准备2个文件:一个是 class.phpmailer.php',另一个是:class.smtp.php //文件导入,及参数获取省去。。。。 $mail = new PHPMailer(true); // the true param means it wi

为了忘却的专栏 1696
上一篇: FMS服务器端和客户端互相调用
下一篇: 网页上的视频打不开
在行进路上
博客等级 码龄10年 17粉丝 119原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值