phpメールクラス、phpmail_PHPチュートリアル
phpメールクラス、phpメール
phpソケットを使用してメールを送信するクラスを作成します。phpプログラムを使用してメールを送信する場合は、シンプルで使いやすいです。
163 サーバーでは、RCPT コマンドで 163 メールボックスが存在するかどうかを確認することもできます。さまざまな用途があります。
まだ考えてません。記録して、困っている友達が参照できるようにします
クラスメール {
/**
*メールで送信できます
*/
public $host;
public $port;
public $user;
public $password;
public $mail_form;
public $rcpt;
public $body;
/**
*ヘッダーに添付されている情報
*/
public $to_name;
public $from_name;
public $subject;
public $html;
public $connection;
public $msg = array() ;
// 実行パラメータ初期化
public function __construct($conf, $rcpt, $header, $body, $html = true) {
try {
$this->host = $conf['host '];
$this->port = $conf['port'];
$this->user = $conf['user'];
$this->password = $conf['password'] ;
$this->rcpt = $rcpt;
$this->to_name = $header['to_name'];
$this->from_name = $header['from_name'];
$this- >subject = $header['subject'];
$this->html = $html;
$this->body =base64_encode($body);
} catch (Exception $e) {
投げる新しい例外($e->getMessage());
}
}
public function connect() {
$this->connection = @fsockopen($this->host, '25', $errno, $errstr, 10);
if (! $this->connection) {
throw new Exception('connect failed!');
}
$greet = $this->callback_code();
}
パブリック関数 helo() {
if($ this->is_connect() &&
$this->send_data('HELO ' . $this->host) &&
$this->callback_code() == 250
{
) true を返す;
} else {
throw new Exception($this->get_callback_msg_lastest());
}
}
public function send_data($cmd) {
if (is_resource($this) ->接続)) {
return @fwrite( $this->connection, $cmd."rn", strlen($cmd) + 2);
}
}
public function auth(){
if ($this->is_connect() &&
$this ->send_data('AUTH LOGIN') && $this->callback_code() == 334 &&
$this->send_data(base64_encode($this->user)) && $this->callback_code() == 334 &&
$this->send_data(base64_encode($this->password)) && $ this->callback_code() == 235 ) {
return true;
} else {
throw new Exception($this->get_callback_msg_lastest());
}
}
public function Mail() {
if ($this->is_connect() &&
$this->send_data("MAIL FROM:<$this->user& gt;") &&
$this->callback_code() == 250
) {
return true;
} else {
throw new Exception($this->get_callback_msg_lastest());
}
}
パブリック関数 is_connect() {
return is_resource($this->connection);
}
パブリック関数 callback_code() {
if ($this->is_connect()) {
$msg = fgets($this->connection);
if (!empty($msg)) {
$code = substr($msg, 0, strpos($msg, ' '));
} else {
戻る ' ';
}
$this->msg[] = $msg;
return $code;
}
}
public function get_callback_msg_lastest() {
return end($this->msg);
}
public function rcpt($rcpt) {
if ($this->is_connect() &&
$this->send_data("RCPT TO:") &&
$this->callback_code() = = 250
) {
return true;
} else {
throw new Exception($this->get_callback_msg_lastest());
}
}
パブリック関数 data() {
if ($this->is_connect() &&
$this->send_data('DATA') &&
$this->call back_code() == 354) {
return true;
} else {
throw new Exception($this->get_callback_msg_lastest());
}
}
public function send_mail() {
試してみてください {
$this->connect();
$this->helo();
$this->auth();
$this->Mail();
if (is_array($this) -> rcpt)) {
foreach ($this->rcpt as $rcpt) {
$this->rcpt($rcpt);
}
} else {
$this->rcpt($this-> rcpt);
}
$this->data();
$header = str_replace("rn" . '.', "rn" . '..', トリム(implode("rn", $this ->get_header())));
$body = str_replace("rn" . '.', "rn" . '..', $this->body);
$body = substr($body, 0, 1) == '.' ? 「。」 。 $body : $body;
$this->send_data($header);
$this->send_data('');
$this->send_data($body);
$this->send_data('.');
if ($this->callback_code() != 250) {
throw new Exception('メール送信失敗!');
}
return true;
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
//ただ能检测同じ邮件服务器上のメールアドレス
public function is_email_exist() {
}
パブリック関数 get_header() {
$header = array( );
$content_type = $this->html ? 'テキスト/html;' : 'テキスト/プレーン;' ;
$headers [] = '日付: ' 。 gmdate('D, j M Y H:i:s') 。 ' +0000';
$to_mail = is_array($this->rcpt) ? implode(',', $this->rcpt) : $this->rcpt;
$headers [] = 'To: "' . '=? utf8?B?' .base64_encode($this->to_name) .'" <' 。 $to_mail 。 '>';
$headers [] = 'From: "' . '=?utf8?B?' .base64_encode($this->from_name) .'" <' 。 $this->ユーザー 。 '>';
$headers [] = '件名: ' 。 '=?utf8?B?' 。 Base64_encode($this->subject) 。 '?=';
$headers [] = 'Content-Type:'.$content_type 。 ' 文字セット=utf8; format=flowed';
$headers [] = 'Content-Transfer-Encoding:base64';
$headers [] = 'Content-Disposition: inline';
return $headers;
}
}
/**
* 関数を使用してクラスをカプセル化する
*/
function send_mail($conf, $rcpt, $header, $body) {
$mail = new mail($conf, $rcpt, $header, $body);
if ($mail->send_mail()) {
echo 'メールを正常に送信しました!';
} else {
echo '失敗しました!';
}
}
$conf = array(
'host' => 'smtp.163.com',
'port' => '25',
'user' => 'z1298703836@163.com',
'パスワード' => 'zeiwei123',
);
$rcpt = array(
'z1298703836@sina.com',
'wei.zen@baisonmail.com '
);
$header = array(
'to_name' => 'willstang',
'from_name' => 'sinawill',
'subject' => 'tst of reo ',
);
$body = '
sfsfsd
';$mail = 新規メール($conf, $rcpt, $header, $body);
$mail ->send_mail();
echo '
';
print_r($mail->msg);
電子メールの送信プロセスとその stmp プロトコルについてよく理解してください
送信内容は 2 つの部分に分かれており、1 つの部分はヘッダーにあり、もう 1 つの部分はメールの本文であるなど、送信の詳細もいくつかあります。

ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

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

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

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

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

ホットトピック









PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、

あなたが経験豊富な PHP 開発者であれば、すでにそこにいて、すでにそれを行っていると感じているかもしれません。あなたは、運用を達成するために、かなりの数のアプリケーションを開発し、数百万行のコードをデバッグし、大量のスクリプトを微調整してきました。

このチュートリアルでは、PHPを使用してXMLドキュメントを効率的に処理する方法を示しています。 XML(拡張可能なマークアップ言語)は、人間の読みやすさとマシン解析の両方に合わせて設計された多用途のテキストベースのマークアップ言語です。一般的にデータストレージに使用されます

JWTは、JSONに基づくオープン標準であり、主にアイデンティティ認証と情報交換のために、当事者間で情報を安全に送信するために使用されます。 1。JWTは、ヘッダー、ペイロード、署名の3つの部分で構成されています。 2。JWTの実用的な原則には、JWTの生成、JWTの検証、ペイロードの解析という3つのステップが含まれます。 3. PHPでの認証にJWTを使用する場合、JWTを生成および検証でき、ユーザーの役割と許可情報を高度な使用に含めることができます。 4.一般的なエラーには、署名検証障害、トークンの有効期限、およびペイロードが大きくなります。デバッグスキルには、デバッグツールの使用とロギングが含まれます。 5.パフォーマンスの最適化とベストプラクティスには、適切な署名アルゴリズムの使用、有効期間を合理的に設定することが含まれます。

文字列は、文字、数字、シンボルを含む一連の文字です。このチュートリアルでは、さまざまな方法を使用してPHPの特定の文字列内の母音の数を計算する方法を学びます。英語の母音は、a、e、i、o、u、そしてそれらは大文字または小文字である可能性があります。 母音とは何ですか? 母音は、特定の発音を表すアルファベットのある文字です。大文字と小文字など、英語には5つの母音があります。 a、e、i、o、u 例1 入力:string = "tutorialspoint" 出力:6 説明する 文字列「TutorialSpoint」の母音は、u、o、i、a、o、iです。合計で6元があります

静的結合(静的::) PHPで後期静的結合(LSB)を実装し、クラスを定義するのではなく、静的コンテキストで呼び出しクラスを参照できるようにします。 1)解析プロセスは実行時に実行されます。2)継承関係のコールクラスを検索します。3)パフォーマンスオーバーヘッドをもたらす可能性があります。

PHPの魔法の方法は何ですか? PHPの魔法の方法には次のものが含まれます。1。\ _ \ _コンストラクト、オブジェクトの初期化に使用されます。 2。\ _ \ _リソースのクリーンアップに使用される破壊。 3。\ _ \ _呼び出し、存在しないメソッド呼び出しを処理します。 4。\ _ \ _ get、dynamic属性アクセスを実装します。 5。\ _ \ _セット、動的属性設定を実装します。これらの方法は、特定の状況で自動的に呼び出され、コードの柔軟性と効率を向上させます。
