完整邮件发送类
class smtp
{
/* Public Variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;
/* Private Variables */
var $sock;
/* Constractor */
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";
$this->sock = FALSE;
}
/* Main Function */
function sendmail($to, $from ,$fromname, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = ""){
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(rn))(.)", "1.3", $body);
$header .= "MIME-Version:1.0rn";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html;charset=utf-8rn";
}
$header .= "To: ".$to."rn";
if ($cc != ""){
$header .= "Cc: ".$cc."rn";
}
$header .= "From: $fromnamern";
$header .= "Subject: ".$subject."rn";
$header .= $additional_headers;
$header .= "Date: ".date("r")."rn";
$header .= "X-Mailer:By Redhat (PHP/".php教程version().")rn";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: rn";
$TO = explode(",", $this->strip_comment($to));
if ($cc != ""){
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}
if ($bcc != ""){
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to){
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)){
$this->log_write("Error: Cannot send email to ".$rcpt_to."n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)){
$this->log_write("E-mail has been sent to n");
}else{
$this->log_write("Error: Cannot send email to n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote hostn");
}
return $sent;
}
/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = ""){
if (!$this->smtp_putcmd("HELO", $helo)){
return $this->smtp_error("sending HELO command");
}
#auth
if($this->auth){
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))){
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass))){
return $this->smtp_error("sending HELO command");
}
}
if (!$this->smtp_putcmd("MAIL", "FROM:")){
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:")){
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA")){
return $this->smtp_error("sending DATA command");
}
if (!$this->smtp_message($header, $body)){
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom()){
return $this->smtp_error("sending
}
if (!$this->smtp_putcmd("QUIT")){
return $this->smtp_error("sending QUIT command");
}
return TRUE;
}
function smtp_sockopen($address){
if ($this->relay_host == ""){
return $this->smtp_sockopen_mx($address);
}
else{
return $this->smtp_sockopen_relay();
}
}
function smtp_sockopen_relay(){
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())){
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."n");
$this->log_write("Error: ".$errstr." (".$errno.")n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."n");
return TRUE;;
}
function smtp_sockopen_mx($address){
$domain = ereg_replace("^.+@([^@]+)$", "1", $address);
if (!@getmxrr($domain, $MXHOSTS)){
$this->log_write("Error: Cannot resolve MX "".$domain.""n");
return FALSE;
}
foreach ($MXHOSTS as $host){
$this->log_write("Trying to ".$host.":".$this->smtp_port."n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())){
$this->log_write("Warning: Cannot connect to mx host ".$host."n");
$this->log_write("Error: ".$errstr." (".$errno.")n");
continue;
}
$this->log_write("Connected to mx host ".$host."n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")n");
return FALSE;
}
function smtp_message($header, $body){
fputs($this->sock, $header."rn".$body);
$this->smtp_debug("> ".str_replace("rn", "n"."> ", $header."n> ".$body."n> "));
return TRUE;
}
function smtp_eom(){
fputs($this->sock, "rn.rn");
$this->smtp_debug(". [EOM]n");
return $this->smtp_ok();
}
function smtp_ok(){
$response = str_replace("rn", "", fgets($this->sock, 512));
$this->smtp_debug($response."n");
if (!ereg("^[23]", $response)){
fputs($this->sock, "QUITrn");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned "".$response.""n");
return FALSE;
}
return TRUE;
}
function smtp_putcmd($cmd, $arg = ""){
if($arg != ""){
if($cmd==""){
$cmd = $arg;
}
else{
$cmd = $cmd." ".$arg;
}
}
fputs($this->sock, $cmd."rn");
$this->smtp_debug("> ".$cmd."n");
return $this->smtp_ok();
}
function smtp_error($string){
$this->log_write("Error: Error occurred while ".$string.".n");
return FALSE;
}
function log_write($message){
$this->smtp_debug($message);
if ($this->log_file == ""){
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))){
$this->smtp_debug("Warning: Cannot open log file "".$this->log_file.""n");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}
function strip_comment($address){//去除"()"
$comment = "([^()]*)";
while (ereg($comment, $address)){
$address = ereg_replace($comment, "", $address);
}
return $address;
}
function get_address($address){
$address = ereg_replace("([trn])+", "", $address);//t 制表符 r 回车符 n 换行符 +匹配前面的子表达式一次或多次
$address = ereg_replace("^.*.*$", "1", $address);
return $address;
}
function smtp_debug($message){
if ($this->debug){
echo $message;
}
}
}

PHP异步发送邮件:避免长时间等待邮件发送完成。导言:在Web开发中,发送邮件是常见的功能之一。但是,由于邮件发送需要与服务器进行通信,往往会导致用户在等待邮件发送完成的过程中出现长时间的等待。为了解决这个问题,我们可以使用PHP异步发送邮件的方式来优化用户体验。本文将介绍如何通过具体的代码示例实现PHP异步发送邮件,并避免长时间的等待。一、理解异步发送邮件

我们最近一直在谈论微软计划添加到其最新操作系统Windows11中的许多功能。但是,不要以为微软只会添加什么也不收回。事实上,这家软件巨头开始删除相当多的旧功能。在宣布计划在Windows12发布之前停用MSDT功能后,雷德蒙德开发人员带来了更多的坏消息。我们实际上是在谈论远程邮件槽旧版工具。当我们说您实际上想知道这一点时,请相信我们。Microsoft已开始在内部版本25314中弃用此功能我们相信您还记得,就在几天前,微软在其新的金丝雀频道发布了内部版本25314。上述版本包含许多新功能

最近,许多用户报告了Outlook邮件卡在发件箱中的问题。即使多次尝试发送电子邮件,问题也没有得到解决。当您看到此问题并检查您的发件箱文件夹时,该消息将卡在那里。电子邮件卡在Outlook发件箱中的可能原因是:电子邮件中的附件超过了大小限制,这会减慢发送过程。邮件服务器的Outlook帐户身份验证问题Outlook或邮件服务器脱机Outlook中的发送/接收设置不正确。其他一些软件正在使用Outlook数据文件。防病毒软件会扫描传出的电子邮件。如果这个问题一直困扰着您并且您无法发送电子邮

作为更新Windows11原生应用程序的一部分,微软计划发布新的Outlook。该应用程序是从头开始制作的,现在正在为预览版做准备,这可能会在微软的Windows11混合活动期间宣布。该项目被称为“ProjectMonarch”,这个新的Outlook已经开发了一年多。这是网络应用程序的重新启动,旨在统一所有现有的Windows电子邮件客户端,例如邮件和日历以及桌面版Outlook。通过OutlookOne,微软希望帮助用户跨不同的桌面平台管理他们的电子邮件。有很多方法可以访问

PHP邮件追踪功能:了解用户对邮件的行为和反馈在现代社会中,电子邮件已经成为人们日常生活和工作中必不可少的一部分。对于企业来说,发送邮件是与客户进行沟通、推广产品或服务的重要方式之一。然而,一封邮件被发送出去后,我们如何知道它是否被收到、被读取,或者用户对邮件内容有何反应?这时,邮件追踪功能就显得尤为重要了。邮件追踪功能可以帮助我们了解用户对邮件的行为和反馈

您是否注意到,当您尝试在 iOS 上删除 Gmail 中的邮件时,您只会看到存档选项?继续阅读以了解如何在 iPhone 上删除 Gmail,而不是在邮件应用中存档。更改使用iPhone 和 iPad上的邮件应用程序归档 Gmail 电子邮件的默认选项的设置完全隐藏在设置中,但一旦你知道去哪里,它就可以快速更改。请记住,本教程适用于通过 iPhone 和 iPad 上的 Apple 邮件应用程序使用 Gmail 的用户。另一种选择是在 iPhone/iPad 上使用 Gmail 应用程序。您甚至

PHP和PHPMAILER:如何实现邮件发送的自动过滤功能?在现代社会中,电子邮件已成为人们交流的重要方式之一。然而,随着电子邮件的流行和广泛使用,垃圾邮件的数量也呈现出爆炸式增长的趋势。垃圾邮件不仅会浪费用户的时间和网络资源,还可能带来病毒和钓鱼行为。因此,在开发邮件发送功能时,加入自动过滤垃圾邮件的功能变得至关重要。本文将介绍如何使用PHP和PHPMai

一些 Windows 用户在尝试将 Gmail 或任何其他电子邮件帐户添加到 Windows PC 上的邮件应用程序时报告了错误消息“出现问题,我们很抱歉,但我们无法做到这一点”以及错误代码0x80070490 在屏幕上。即使经过多次尝试,客户也无法将任何电子邮件帐户添加到他们的邮件应用程序中。用户非常不满意,并且不确定如何从这里转移。在邮件应用程序中添加电子邮件帐户时出现此错误的可能原因可能是系统数据文件损坏、邮件应用程序的一些内部问题、过时的邮件应用程序等。在分析了上述可能导致此错误的原因后


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器