PHPメールクラス
コード
//送信邮件のクラス
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;
/* プライベート 変数 */
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: ".$to."rn";
if ($cc != "") {
$header .= "Cc: ".$cc."rn";
}
$header .= "From: $fromrn";
$header .= "件名: ".$subject."rn";
$header .= $Additional_headers;
$header .= "日付: ".date("r")."rn";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")rn";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">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("エラー: ".$rcpt_to."n");
$sent = FALSE;
続けます。
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E -メールは<に送信されました;".$rcpt_to.">n");
} else {
$this->log_write("エラー: n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("リモートホストnから切断されました");
}
$sent を返す;
}
/* プライベート 関数 */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helああ)) {
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:<".$from.">")) { return $this->smtp_error("MAIL を送信中FROM コマンド」);
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$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("送信中
}
if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("sending QUIT command");
}
TRUEを返します。
}
関数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 を返します。
}
関数 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".">gt; ", $header."n>gt; ".$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->sock, 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(">gt; ".$cmd."n");
return $this->smtp_ok();
}
function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$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");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
TRUE を返します。
}
関数strip_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;
}
}
}
?>
コード
require('mail.class.php');
$smtpserver = "smtp.126.com";//SMTP サービス
$smtpserverport =25;//SMTP サービス端末
$smtpusermail = "777@126.com";//SMTP サービスの用人邮箱
$smtpemailto = "777@126.com";//送信先
$smtpuser = "777@126.com";//SMTP サーバーのユーザー アカウント
$smtppass = "777777";//ユーザーSMTP サーバーのパスワード
$mailsubject = "テストメールの件名";//メールの件名
$mailbody = "
gt;テストメールの内容
";//メールの内容$mailtype = "HTML";/ /メール形式 (HTML/TXT)、TXT はテキストメールです
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//ここで true は認証が使用されることを意味し、それ以外の場合は認証が使用されます使用されません
$smtp->debug = true;//送信されたデバッグ情報を表示するかどうか
echo $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype); >

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

ホットトピック

Laravelは、直感的なフラッシュメソッドを使用して、一時的なセッションデータの処理を簡素化します。これは、アプリケーション内に簡単なメッセージ、アラート、または通知を表示するのに最適です。 データは、デフォルトで次の要求のためにのみ持続します。 $リクエスト -

PHPロギングは、Webアプリケーションの監視とデバッグ、および重要なイベント、エラー、ランタイムの動作をキャプチャするために不可欠です。システムのパフォーマンスに関する貴重な洞察を提供し、問題の特定に役立ち、より速いトラブルシューティングをサポートします

PHPクライアントURL(CURL)拡張機能は、開発者にとって強力なツールであり、リモートサーバーやREST APIとのシームレスな対話を可能にします。尊敬されるマルチプロトコルファイル転送ライブラリであるLibcurlを活用することにより、PHP Curlは効率的なexecuを促進します

Laravelは簡潔なHTTP応答シミュレーション構文を提供し、HTTP相互作用テストを簡素化します。このアプローチは、テストシミュレーションをより直感的にしながら、コード冗長性を大幅に削減します。 基本的な実装は、さまざまな応答タイプのショートカットを提供します。 Illuminate \ support \ facades \ httpを使用します。 http :: fake([[ 'google.com' => 'hello world'、 'github.com' => ['foo' => 'bar']、 'forge.laravel.com' =>

顧客の最も差し迫った問題にリアルタイムでインスタントソリューションを提供したいですか? ライブチャットを使用すると、顧客とのリアルタイムな会話を行い、すぐに問題を解決できます。それはあなたがあなたのカスタムにより速いサービスを提供することを可能にします

記事では、PHP 5.3で導入されたPHPの後期静的結合(LSB)について説明し、より柔軟な継承を求める静的メソッドコールのランタイム解像度を可能にします。 LSBの実用的なアプリケーションと潜在的なパフォーマ

この記事では、フレームワークにカスタム機能を追加し、アーキテクチャの理解、拡張ポイントの識別、統合とデバッグのベストプラクティスに焦点を当てています。
