class smtp
{
/* パブリック変数 */
var $smtp_port;
var $time_out;
var $ホスト名;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;
/* プライベート変数 */
var $sock;
/* コンストラクター */
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; // fsockopen() で使用されます
#
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
#
$this->host_name = "localhost"; // HELO コマンドで使用されます
$this->log_file = "";
$this->靴下 = FALSE;
}
/* Main Function */
function sendmail($to, $from, $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 バージョン:1.0rn";
if($mailtype=="HTML"){
$header .= "Content-Type:text/htmlrn";
}
$header .= "宛先: ".$to."rn";
if ($cc != "") {
$header .= "Cc: ".$cc."rn";
}
$header .= "From: $from;rn";
$header .= "件名: ".$subject."rn";
$header .= $Additional_headers;
$header .= "日付: ".date("r")."rn";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")rn";
list($msec, $sec) =explode(" ", microtime());
$header .= "メッセージ ID: gt;;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)));
}
$送信 = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("エラー: ".$rcpt_to."n にメールを送信できません");
$送信 = FALSE;
続けてください。
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("メールは < に送信されました;".$rcpt_to.">>;n");
} else {
$this->log_write("エラー: ;n"); にメールを送信できません。
$送信 = FALSE;
}
fclose($this->靴下);
$this->log_write("リモートホストnから切断されました");
}
$sent を返します。
}
/* プライベート関数 */
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("HELO コマンドを送信中");
}
if (!$this->smtp_putcmd("",base64_encode($this->pass))) {
return $this->smtp_error("HELO コマンドを送信中");
}
}
#
if (!$this->smtp_putcmd("MAIL", "FROM:;")) {
return $this->smtp_error("送信中MAIL FROM コマンド");
}
if (!$this->smtp_putcmd("RCPT", "TO:;")) {
return $this->smtp_error("RCPT TO コマンドを送信中" );
}
if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("DATA コマンドを送信中");
}
if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("メッセージ送信中");
}
if (!$this->smtp_eom()) {
return $this->smtp_error("送信中
}
if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("QUIT コマンドを送信中");
}
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("エラー: リレー ホスト ".$this->relay_host" に接続できません。"n ");
$this->log_write("エラー: ".$errstr." (".$errno.")n");
FALSEを返します。
}
$this->log_write("リレー ホスト ".$this->relay_host."n" に接続しました);
TRUEを返します。
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS)) {
$this->log_write("エラー: MX "".$domain.""n");
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("警告: mx ホスト ".$host."n"); に接続できません。
$this->log_write("エラー: ".$errstr." (".$errno.")n");
続けてください。
}
$this->log_write("MX ホスト ".$host."n"); に接続しました。
TRUEを返します。
}
$this->log_write("エラー: どの mx ホストにも接続できません (".implode(", ", $MXHOSTS).")n");
FALSEを返します。
}
function smtp_message($header, $body)
{
fputs($this->sock, $header."rn".$body);
$this->smtp_debug(">; ".str_replace("rn", "n".">>; ", $header."n>; ".$body."n>; "));
TRUEを返します。
}
関数 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->靴下, 512);
$this->log_write("エラー: リモート ホストが "".$response.""n") を返しました。
FALSEを返します。
}
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("エラー: ".$string.".n");
FALSEを返します。
}
関数 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("警告: ログ ファイルを開けません "".$this->log_file.""n");
FALSEを返します。
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
TRUEを返します。
}
functionstrip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}
$address を返します。
}
function get_address($address)
{
$address = ereg_replace("([ trn])+", "", $address);
$address = ereg_replace("^.*;.*$", "\1", $address);
$address を返します;
}
function smtp_debug($message)
{
if ($this->debug) {
echo $message;
}
}
}
function sendmail($smtpserver,$smtpuser,$smtppass,$smtpemailto,$smtpusermail, $mailsubject, $mailbody){
$smtp = new smtp($smtpserver,25,true,$smtpuser,$ smtppass);
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, "HTML");
}
//sendmail("smtp.126.com","test@126.com","パスワード","1034555083@qq.com","test@126.com","タイトル","本文");
//$smtpserver = "SMTP.163.com"; // 您的 smtp サーバーの地址
$smtpserver="smtp.qq.com";
$ポート = 25; //smtp サービスのポート口、一般的には 25
$smtpuser = "116206443@emil.com"; //您登录smtpサービス务器の用户名
$smtppwd = "123456789oiuy"; //您登录smtpサービス务器の秘密コード
$mailtype = "TXT"; // プラグインの種類、選択可能なのは TXT または HTML です。TXT 表示はテキストブックのプラグイン、HTML 表示は html 形式のプラグインです
$sender = "116206443@qq.com";
//発行者、一般的には登录smtpサーバーのユーザー名($smtpuser)と同じかどうか、smtpサーバーの設定が原因で送信損失が発生する可能性があります
$smtp = new smtp($smtpserver,$port,true,$ smtpuser、$smtppwd、$sender);
$smtp->debug = true; // 否か启调试、只今测试程序時使用,正式使用時请此行注释
$to = "116206443@qq.com"; //收件人
$subject = "你好";
$body = "测试送信内容 ";
$send=$smtp->sendmail($to,$sender,$subject,$body,$mailtype);
if($send==1){
echo "邮件送信成功";
}else{
echo "邮件送信失败
";
//echo "原因:".$this->smtp->logs;
}
?>

データベースストレージセッションを使用することの主な利点には、持続性、スケーラビリティ、セキュリティが含まれます。 1。永続性:サーバーが再起動しても、セッションデータは変更されないままになります。 2。スケーラビリティ:分散システムに適用され、セッションデータが複数のサーバー間で同期されるようにします。 3。セキュリティ:データベースは、機密情報を保護するための暗号化されたストレージを提供します。

PHPでのカスタムセッション処理の実装は、SessionHandlerInterfaceインターフェイスを実装することで実行できます。具体的な手順には、次のものが含まれます。1)CussentsessionHandlerなどのSessionHandlerInterfaceを実装するクラスの作成。 2)セッションデータのライフサイクルとストレージ方法を定義するためのインターフェイス(オープン、クローズ、読み取り、書き込み、破壊、GCなど)の書き換え方法。 3)PHPスクリプトでカスタムセッションプロセッサを登録し、セッションを開始します。これにより、データをMySQLやRedisなどのメディアに保存して、パフォーマンス、セキュリティ、スケーラビリティを改善できます。

SessionIDは、ユーザーセッションのステータスを追跡するためにWebアプリケーションで使用されるメカニズムです。 1.ユーザーとサーバー間の複数のインタラクション中にユーザーのID情報を維持するために使用されるランダムに生成された文字列です。 2。サーバーは、ユーザーの複数のリクエストでこれらの要求を識別および関連付けるのに役立つCookieまたはURLパラメーターを介してクライアントに生成および送信します。 3.生成は通常、ランダムアルゴリズムを使用して、一意性と予測不可能性を確保します。 4.実際の開発では、Redisなどのメモリ内データベースを使用してセッションデータを保存してパフォーマンスとセキュリティを改善できます。

APIなどのステートレス環境でのセッションの管理は、JWTまたはCookieを使用して達成できます。 1。JWTは、無国籍とスケーラビリティに適していますが、ビッグデータに関してはサイズが大きいです。 2.cookiesはより伝統的で実装が簡単ですが、セキュリティを確保するために慎重に構成する必要があります。

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

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

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

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


ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

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

メモ帳++7.3.1
使いやすく無料のコードエディター

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

ホットトピック









