ホームページ バックエンド開発 PHPチュートリアル 彼女は私の罪です gtp smtp メール送信例

彼女は私の罪です gtp smtp メール送信例

Jul 29, 2016 am 08:34 AM

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("< $line");
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"))<=0)
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: <".$sender.">"))
return(0);
if(!IsSet ($this->esmtp_extensions["PIPELINING"])
&& $this->VerifyResultLines("250")<=0)
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:<".$recipient.">"))
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」 ))<=0)
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")<=0)
return(0);
$this->state="SendingData";
return(1);
}
関数 PrepareData($data,&$output)
{
$length=strlen(&$data);
for($output="",$position=0;$position<$length;)
{
$next_position =$length;
for($current=$position;$current<$length;$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")<=0)
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")<=0)
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")<=0))
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 までご連絡ください。

ホット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

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

SublimeText3 中国語版

SublimeText3 中国語版

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

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

PHPとPython:2つの一般的なプログラミング言語を比較します PHPとPython:2つの一般的なプログラミング言語を比較します Apr 14, 2025 am 12:13 AM

PHPとPythonにはそれぞれ独自の利点があり、プロジェクトの要件に従って選択します。 1.PHPは、特にWebサイトの迅速な開発とメンテナンスに適しています。 2。Pythonは、データサイエンス、機械学習、人工知能に適しており、簡潔な構文を備えており、初心者に適しています。

PHPでの安全なパスワードハッシュ(例:Password_hash、password_verify)を説明します。 MD5またはSHA1を使用してみませんか? PHPでの安全なパスワードハッシュ(例:Password_hash、password_verify)を説明します。 MD5またはSHA1を使用してみませんか? Apr 17, 2025 am 12:06 AM

PHPでは、Password_hashとpassword_verify関数を使用して安全なパスワードハッシュを実装する必要があり、MD5またはSHA1を使用しないでください。 1)password_hashセキュリティを強化するために、塩値を含むハッシュを生成します。 2)password_verifyハッシュ値を比較して、パスワードを確認し、セキュリティを確保します。 3)MD5とSHA1は脆弱であり、塩の値が不足しており、最新のパスワードセキュリティには適していません。

アクション中のPHP:実際の例とアプリケーション アクション中のPHP:実際の例とアプリケーション Apr 14, 2025 am 12:19 AM

PHPは、電子商取引、コンテンツ管理システム、API開発で広く使用されています。 1)eコマース:ショッピングカート機能と支払い処理に使用。 2)コンテンツ管理システム:動的コンテンツの生成とユーザー管理に使用されます。 3)API開発:RESTFUL API開発とAPIセキュリティに使用されます。パフォーマンスの最適化とベストプラクティスを通じて、PHPアプリケーションの効率と保守性が向上します。

PHP:Web開発の重要な言語 PHP:Web開発の重要な言語 Apr 13, 2025 am 12:08 AM

PHPは、サーバー側で広く使用されているスクリプト言語で、特にWeb開発に適しています。 1.PHPは、HTMLを埋め込み、HTTP要求と応答を処理し、さまざまなデータベースをサポートできます。 2.PHPは、ダイナミックWebコンテンツ、プロセスフォームデータ、アクセスデータベースなどを生成するために使用され、強力なコミュニティサポートとオープンソースリソースを備えています。 3。PHPは解釈された言語であり、実行プロセスには語彙分析、文法分析、編集、実行が含まれます。 4.PHPは、ユーザー登録システムなどの高度なアプリケーションについてMySQLと組み合わせることができます。 5。PHPをデバッグするときは、error_reporting()やvar_dump()などの関数を使用できます。 6. PHPコードを最適化して、キャッシュメカニズムを使用し、データベースクエリを最適化し、組み込み関数を使用します。 7

PHPの永続的な関連性:それはまだ生きていますか? PHPの永続的な関連性:それはまだ生きていますか? Apr 14, 2025 am 12:12 AM

PHPは依然として動的であり、現代のプログラミングの分野で重要な位置を占めています。 1)PHPのシンプルさと強力なコミュニティサポートにより、Web開発で広く使用されています。 2)その柔軟性と安定性により、Webフォーム、データベース操作、ファイル処理の処理において顕著になります。 3)PHPは、初心者や経験豊富な開発者に適した、常に進化し、最適化しています。

スカラータイプ、リターンタイプ、ユニオンタイプ、ヌル可能なタイプなど、PHPタイプのヒントはどのように機能しますか? スカラータイプ、リターンタイプ、ユニオンタイプ、ヌル可能なタイプなど、PHPタイプのヒントはどのように機能しますか? Apr 17, 2025 am 12:25 AM

PHPタイプは、コードの品質と読みやすさを向上させるためのプロンプトがあります。 1)スカラータイプのヒント:php7.0であるため、基本データ型は、int、floatなどの関数パラメーターで指定できます。 3)ユニオンタイプのプロンプト:PHP8.0であるため、関数パラメーターまたは戻り値で複数のタイプを指定することができます。 4)Nullable Typeプロンプト:null値を含めることができ、null値を返す可能性のある機能を処理できます。

PHPおよびPython:コードの例と比較 PHPおよびPython:コードの例と比較 Apr 15, 2025 am 12:07 AM

PHPとPythonには独自の利点と短所があり、選択はプロジェクトのニーズと個人的な好みに依存します。 1.PHPは、大規模なWebアプリケーションの迅速な開発とメンテナンスに適しています。 2。Pythonは、データサイエンスと機械学習の分野を支配しています。

PHP対その他の言語:比較 PHP対その他の言語:比較 Apr 13, 2025 am 12:19 AM

PHPは、特に迅速な開発や動的なコンテンツの処理に適していますが、データサイエンスとエンタープライズレベルのアプリケーションには良くありません。 Pythonと比較して、PHPはWeb開発においてより多くの利点がありますが、データサイエンスの分野ではPythonほど良くありません。 Javaと比較して、PHPはエンタープライズレベルのアプリケーションでより悪化しますが、Web開発により柔軟性があります。 JavaScriptと比較して、PHPはバックエンド開発により簡潔ですが、フロントエンド開発のJavaScriptほど良くありません。

See all articles