host_name="mail.xiaocui.com"; $smtp->localhost="localhost";$from="webmaster@xiaocui.com";$to="root@xiaocui.com";if($smtp->送信"/> host_name="mail.xiaocui.com"; $smtp->localhost="localhost";$from="webmaster@xiaocui.com";$to="root@xiaocui.com";if($smtp->送信">
検索
ホームページバックエンド開発PHPチュートリアル彼女は私の罪です gtp smtp メール送信例

test_smtp.php

require("smtp.php");
$smtp=new smtp_class;
$smtp->host_name="mail.xiaocui.com";
$smtp->localhost="localhost ";
$from="webmaster@xiaocui.com";
$to="root@xiaocui.com";
if($smtp->SendMessage(
$from,
array(
$to
),
array(
"From: $from",
"To: $to",
"件名: Manuel Lemos の SMTP クラスのテスト"
),
"Hello $to,nnこれは、SMTP クラスが次のとおりであることをお知らせするためのものです。正常に動作しています。nnBye.n"))
echo "$to OK.n にメッセージを送信しました。";
else
echo "$to.n にメッセージを送信できませんでした。エラー: ".$smtp->error."n "
?>
smtp.php

class smtp_class
{
var $host_name="";
var $host_port=25;
var $localhost="";
var $timeout=0;
var $error="";
var $debug=1;
var $esmtp=1;
var $esmtp_host="";
var $esmtp_extensi>var $maximum_piped_recipients=100;
/* プライベート変数 - アクセスしないでください */
var $state="Disconnected";
var $c>var $pending_recipients=0;
/* プライベート メソッド - 呼び出さないでください */
Function OutputDebug($message)
{
echo $message,"
n";
}
関数 GetLine()
{
for($line="";;)
{
if(feof($this->connection))
{
$this->error="到達ソケットからの読み取り中のストリームの終わり";
return(0);
}
if(($data=fgets($this->connection,100))==false)
{
$this->error ="ソケットから行を読み取ることができませんでした";
return(0);
}
$line.=$data;
$length=strlen($line);
if($length>=2
&& substr ($line,$length-2,2)=="rn")
{
$line=substr($line,0,$length-2);
if($this->debug)
$this- >OutputDebug(" return($line);
}
}
}
Function PutLine($line)
{
if($this->debug)
$this->OutputDebug("> $line ");
if(!fputs($this->connection,"$linern"))
{
$this->error="ソケットに行を書き込むことができませんでした";
return(0);
}
return(1);
}
関数 PutData($data)
{
if(strlen($data))
{
if($this->debug)
$this->OutputDebug("> ; $data");
if(!fputs($this->connection,$data))
{
$this->error="ソケットにデータを書き込むことができませんでした";
return(0) ;
}
}
return(1);
}
Function VerifyResultLines($code,$resp>{
if(GetType($responses)!="array")
$resp> Unset($match_code);
while (($line=$this->GetLine($this->connection)))
{
if(IsSet($match_code))
{
if(strcmp(strtok($line," -"),$ match_code)))
{
$this->error=$line;
return(0);
}
}
else
{
$match_code=strtok($line," -");
if(GetType($ code)=="array")
{
for($codes=0;$codes if($codes> =count($code))
{
$this->error=$line;
return(0);
}
}
else
{
if(strcmp($match_code,$code))
{
$this->error=$line;
return(0);
}
}
}
$responses[]=strtok(" ");
if(!strcmp($match_code,strtok($line," ")))
return(1);
}
return(-1);
}
Function FlushRecipients()
{
if($ this->pending_sender)
{
if($this->VerifyResultLines("250") return(0);
$this->pending_sender=0;
}
for(;$ this->pending_recipients;$this->pending_recipients--)
{
if($this->VerifyResultLines(array("250","251")) return(0);
}
return(1);
}
/* パブリック メソッド */
Function Connect()
{
$this->error=$error="";
$this->esmtp_host="";
$ this->esmtp_extensi> if(!($this->c ? fsockopen($this->host_name,$this->host_port,&$errno,&$error,$this->timeout) : fsockopen ($this->host_name,$this->host_port))))
{
switch($error)
{
case -3:
$this->error="-3 ソケットを作成できませんでした" ;
return(0);
case -4:
$this->error="-4 ホスト名 "".$host_name." の DNS ルックアップに失敗しました";
return(0);
case -5:
$this->error="-5 接続が拒否されたかタイムアウトしました";
return(0);
case -6:
$this->error="-6 fdopen() 呼び出しが失敗しました";
return(0 );
case -7:
$this->error="-7 setvbuf() call failed";
return(0);
default:
$this->error=$error." に接続できませんでした。ホスト "".$this->host_name.""";
return(0);
}
}
else
{
if(!strcmp($localhost=$this->localhost,"")
&& !strcmp($localhost=getenv("SERVER_NAME"),"")
&& !strcmp($localhost=getenv("HOST"),""))
$localhost="localhost";
$success=0;
if($this->VerifyResultLines("220")>0)
{
if($this->esmtp)
{
$resp> if($this->PutLine("EHLO $localhost" )
&& $this->VerifyResultLines("250",&$responses)>0)
{
$this->esmtp_host=strtok($responses[0]," ");
for($resp> {
$extension=strtoupper(strtok($responses[$response]," "));
$this->esmtp_extensions[$extension]=strtok("");
$success=1;
}
}
if(!$success
&& $this->PutLine("HELO $localhost")
&& $this->VerifyResultLines("250")>0)
$success=1;
}
if( $success)
{
$this->state="接続済み";
return(1);
}
else
{
fclose($this->connection);
$this->c> $this->state="切断されました";
return(0);
}
}
}
関数 MailFrom( $sender)
{
if(strcmp($this->state,"接続済み"))
{
$this->error="接続が初期状態ではありません";
return(0);
}
$this->error="";
if(!$this->PutLine("MAIL FROM: "))
return(0);
if(!IsSet ($this->esmtp_extensions["PIPELINING"])
&& $this->VerifyResultLines("250") return(0);
$this->state="SenderSet";
if(IsSet($this->esmtp_extensions["PIPELINING"]))
$this->pending_sender=1;
$this->pending_recipients=0;
return(1);
}
Function SetRecipient($受信者)
{
switch($this->state)
{
case "SenderSet":
case "RecipientSet":
break;
default:
$this->error="接続が受信者の設定にありませんstate";
return(0);
}
$this->error="";
if(!$this->PutLine("RCPT TO:"))
return(0);
if(IsSet($this->esmtp_extensions["PIPELINING"]))
{
$this->pending_recipients++;
if($this->pending_recipients>=$this-> Maximum_piped_recipients)
{
if(!$this->FlushRecipients())
return(0);
}
}
else
{
if($this->>VerifyResultLines(array("250", 「251」 )) return(0);
}
$this->state="RecipientSet";
return(1);
}
Function StartData()
{
if(strcmp($this- >state,"RecipientSet"))
{
$this->error="接続はデータ送信開始状態ではありません";
return(0);
}
$this->error="";
if(!$this->PutLine("DATA"))
return(0);
if($this->pending_recipients)
{
if(!$this->FlushRecipients())
return( 0);
}
if($this->VerifyResultLines("354") return(0);
$this->state="SendingData";
return(1);
}
関数 PrepareData($data,&$output)
{
$length=strlen(&$data);
for($output="",$position=0;$position {
$next_position =$length;
for($current=$position;$current {
switch($data[$current])
{
case "n":
$next_position=$current+1 ;
break 2;
case "r":
$next_position=$current+1;
if($data[$next_position]=="n")
$next_position++;
break 2;
}
}
if( $data[$position]==".")
$output.=".";
$output.=substr(&$data,$position,$current-$position)."rn";
$position= $next_position;
}
}
Function SendData($data)
{
if(strcmp($this->state,"SendingData"))
{
$this->error="接続が送信中にありませんデータ状態";
return(0);
}
$this->error="";
return($this->PutData(&$data));
}
関数 EndSendingData()
{
if(strcmp($this->state,"SendingData"))
{
$this->error="接続はデータ送信状態ではありません";
return(0) ;
}
$this->error="";
if(!$this->PutLine("rn.")
|| $this->VerifyResultLines("250") return(0);
$this->state="接続済み";
return(1);
}
Function ResetConnection()
{
switch($this->state)
{
case "接続済み":
return(1);
case "SendingData":
$this->error="データ送信中に接続をリセットできません";
return(0);
case "Disconnected":
$this->error ="確立される前に接続をリセットすることはできません";
return(0);
}
$this->error="";
if(!$this->PutLine("RSET")
|| $this->VerifyResultLines("250") return(0);
$this->state="接続済み";
return(1);
}
Function Disconnect($quit=1) )
{
if(!strcmp($this->state,"切断"))
{
$this->error="以前に SMTP 接続が確立されていませんでした";
return(0);
}
$this->error="";
if(!strcmp($this->state,"接続済み")
&& $quit
&& (!$this->PutLine("QUIT")
|| $this->VerifyResultLines("221") return(0);
fclose($this->connection);
$this->c> $this->state="切断されました";
return(1);
}
関数 SendMessage($sender,$recipients,$headers,$body)
{
if(($success=$this->Connect()))
{
if (($success=$this->MailFrom($sender)))
{
for($recipient=0;$recipient {
if(!($success=$) this->SetRecipient($recipients[$recipient])))
break;
}
if($success
&& ($success=$this->StartData()))
{
for($header_data=" ",$header=0;$header $header_data.=$headers[$header]."rn";
if(($success=$this->SendData($ header_data."rn")))
{
$this->PrepareData($body,&$body_data);
$success=$this->SendData($body_data);
}
if($success)
$success=$this->EndSendingData();
}
}
$disc> if($success)
$success=$disconnect_success;
}
return($success);
}
};
?>

以上、彼女は私の罪です gtp smtp 邮件送信一例を含み、彼女は私の罪です gtp の側面の内容を含み、PHP 教程に関心のある友人の助けとなることを望みます。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
セッションに関連するクロスサイトスクリプティング(XSS)攻撃からどのように保護できますか?セッションに関連するクロスサイトスクリプティング(XSS)攻撃からどのように保護できますか?Apr 23, 2025 am 12:16 AM

セッション関連のXSS攻撃からアプリケーションを保護するには、次の測定が必要です。1。セッションCookieを保護するためにHTTPonlyとセキュアフラグを設定します。 2。すべてのユーザー入力のエクスポートコード。 3.コンテンツセキュリティポリシー(CSP)を実装して、スクリプトソースを制限します。これらのポリシーを通じて、セッション関連のXSS攻撃を効果的に保護し、ユーザーデータを確保できます。

PHPセッションのパフォーマンスを最適化するにはどうすればよいですか?PHPセッションのパフォーマンスを最適化するにはどうすればよいですか?Apr 23, 2025 am 12:13 AM

PHPセッションのパフォーマンスを最適化する方法は次のとおりです。1。遅延セッション開始、2。データベースを使用してセッションを保存します。これらの戦略は、高い並行性環境でのアプリケーションの効率を大幅に改善できます。

session.gc_maxlifetime構成設定とは何ですか?session.gc_maxlifetime構成設定とは何ですか?Apr 23, 2025 am 12:10 AM

thesession.gc_maxlifettinginttinginphpdethinesthelifsessessiondata、setinseconds.1)it'sconfiguredinphp.iniorviaini_set()。 2)AbalanceSneededToAvoidPerformanceIssues andunexpectedLogouts.3)php'sgarbagecollectionisisprobabilistic、影響を受けたBygc_probabi

PHPでセッション名をどのように構成しますか?PHPでセッション名をどのように構成しますか?Apr 23, 2025 am 12:08 AM

PHPでは、session_name()関数を使用してセッション名を構成できます。特定の手順は次のとおりです。1。session_name()関数を使用して、session_name( "my_session")などのセッション名を設定します。 2。セッション名を設定した後、session_start()を呼び出してセッションを開始します。セッション名の構成は、複数のアプリケーション間のセッションデータの競合を回避し、セキュリティを強化することができますが、セッション名の一意性、セキュリティ、長さ、設定タイミングに注意してください。

セッションIDをどのくらいの頻度で再生する必要がありますか?セッションIDをどのくらいの頻度で再生する必要がありますか?Apr 23, 2025 am 12:03 AM

セッションIDは、機密操作の前、30分ごとにログイン時に定期的に再生する必要があります。 1.セッション固定攻撃を防ぐためにログインするときにセッションIDを再生します。 2。安全性を向上させるために、敏感な操作の前に再生します。 3.定期的な再生は長期的な利用リスクを減らしますが、ユーザーエクスペリエンスの重量を量る必要があります。

PHPでセッションCookieパラメーターをどのように設定しますか?PHPでセッションCookieパラメーターをどのように設定しますか?Apr 22, 2025 pm 05:33 PM

PHPのセッションCookieパラメーターの設定は、session_set_cookie_params()関数を通じて達成できます。 1)この関数を使用して、有効期限、パス、ドメイン名、セキュリティフラグなどのパラメーターを設定します。 2)session_start()を呼び出して、パラメーターを有効にします。 3)ユーザーログインステータスなど、ニーズに応じてパラメーターを動的に調整します。 4)セキュリティを改善するために、セキュアとhttponlyフラグを設定することに注意してください。

PHPでセッションを使用する主な目的は何ですか?PHPでセッションを使用する主な目的は何ですか?Apr 22, 2025 pm 05:25 PM

PHPでセッションを使用する主な目的は、異なるページ間でユーザーのステータスを維持することです。 1)セッションはsession_start()関数を介して開始され、一意のセッションIDを作成し、ユーザーCookieに保存します。 2)セッションデータはサーバーに保存され、ログインステータスやショッピングカートのコンテンツなど、さまざまなリクエスト間でデータを渡すことができます。

サブドメイン間でセッションをどのように共有できますか?サブドメイン間でセッションをどのように共有できますか?Apr 22, 2025 pm 05:21 PM

サブドメイン間でセッションを共有する方法は?一般的なドメイン名にセッションCookieを設定することにより実装されます。 1.セッションCookieのドメインをサーバー側の.example.comに設定します。 2。メモリ、データベース、分散キャッシュなど、適切なセッションストレージ方法を選択します。 3. Cookieを介してセッションIDを渡すと、サーバーはIDに基づいてセッションデータを取得および更新します。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

DVWA

DVWA

Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

mPDF

mPDF

mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。