<?php class SendM{ private $Mailhost,$Mailuser,$Mailpwd,$Mailport,$Mailtimeout,$ms,$ending = "\r\n",$endingc="\n"; function __construct($Mailhost,$Mailuser,$Mailpwd,$Mailport,$Mailtimeout){ $this->Mailhost=$Mailhost; $this->Mailuser=$Mailuser; $this->Mailpwd=$Mailpwd; $this->Mailport=$Mailport; $this->Mailtimeout=$Mailtimeout; $this->ConnectSmtpServer(); } private function ConnectSmtpServer(){ if(!is_string($this->Mailhost)){ settype(trim($this->Mailhost),"string"); } if(!is_integer($this->Mailport)){ settype(trim($this->Mailport),"integer"); } if(!is_integer($this->Mailtimeout)){ settype(trim($this->Mailtimeout),"integer"); } $this->ms=@fsockopen($this->Mailhost,$this->Mailport,$this->errorno,$this->errorstr,$this->Mailtimeout); if(substr(PHP_OS,0,3) != "WIN"){ stream_set_timeout($this->ms, $this->Mailtimeout, 0);} $rcp = $this->get_echo(); fputs($this->ms,"ehlo bobo".$this->ending); $rcp = $this->get_echo(); if(substr($rcp,0,3)!='250'){ return false; } fputs($this->ms,'auth login'.$this->ending); $rcp = $this->get_echo(); if(substr($rcp,0,3)=='334'){ $this->Auth($this->Mailuser,$this->Mailpwd); }else{ return false; } } private function Auth($Mailuser,$Mailpwd){ $this->Mailuseren=base64_encode($Mailuser); $this->Mailpwden=base64_encode($Mailpwd); fputs($this->ms,$this->Mailuseren.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,$this->Mailpwden.$this->ending); $rcp = $this->get_echo(); } private function get_echo(){ $edata=""; while($estr=@fgets($this->ms,600)){ $edata .= $estr; if(substr($estr,3,1) == " ") { break; } } return $edata; } public function Send($to,$subject,$connect){ $host=explode('.',$this->Mailhost); $fromaddress=$this->Mailuser.'@'.$host[1].'.'.$host[2]; fputs($this->ms,'mail from:<'.$fromaddress.'>'.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,'rcpt to:<'.$to.'>'.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,'data'.$this->ending); $rcp = $this->get_echo(); fputs($this->ms,"to:$to".$this->endingc); fputs($this->ms,"from:$fromaddress".$this->endingc); fputs($this->ms,"subject:$subject".$this->endingc.$this->endingc); fputs($this->ms,"$connect".$this->endingc); fputs($this->ms,'.'.$this->ending); $rcp = $this->get_echo(); if(substr($rcp,0,3)=='250'){header("Location:main_pro.php?act=msg&errors=on&msg=邮件发送成功!已成功提交至对方服务器!"); }else{ header("Location:main_pro.php?act=msg&errors=on&msg=很遗憾,邮件发送失败了!请检查邮件账户配置是否正确!"); } } } ?>
これはメール送信用の php クラスです。必要な友達はダウンロードして使用してください。
使用説明:
$m= new SendM('smtp サーバー アドレス', 'アカウント', 'パスワード', ポート (int), タイムアウト再試行時間 (int));
$m->Send('受信者のメール', '件名', 'メール本文');
使用例:
$m= new SendM ('smtp .yeah.net','testuser','testuserpwd',25,30);
$m->Send('a@coolmr.com ','テストメール','これはメール送信用のテストメールです。ご支援ありがとうございます');
このサイトのすべてのリソースはネチズンによって提供されたもの、または主要なダウンロード サイトによって転載されたものです。ソフトウェアの整合性をご自身で確認してください。このサイトのすべてのリソースは学習の参考のみを目的としています。商業目的で使用しないでください。そうでない場合は、すべての結果に対して責任を負うことになります。侵害がある場合は、削除するためにご連絡ください。連絡先情報: admin@php.cn
関連記事
13 Jun 2016
php で SMTP を使用して電子メールを送信するためのコード。最近のプロジェクトでは、電子メールを送信するために SMTP が必要でした。以前のライブラリ クラスはもう存在しません。pear をインストールしたり、pear の net/smtp クラスを使用したりするのは面倒です。 discuz から直接抽出するだけです
13 Jun 2016
誰かが参照用に電子メール アドレスを確認するための正規表現を送ってくれませんか? 私が理解している電子メール ルール [email protected] /^[w-] @[w-] .[w-] $/ (これは機能しますか? ?)いくつかの特権メールボックスがありますが、それらを考慮する必要がありますか? QQ メールボックスは VIP メールボックス ドメイン名を開始しており、メンバーは排他的です。
13 Jun 2016
PHP で SMTP 経由で電子メールを送信するためのクラスはテストに合格しました。 smtp.php コードは次のとおりです。ユーザー;
13 Jun 2016
詳細な手順を記載した電子メールを送信するためのフル機能の PHP コード。 ?php classEmail{ //---グローバル変数を設定します var$mailTo="";//受信者 var$mailCC="";//Cc var$mailBCC="";//シークレット Cc var$mailFrom =""; //送信者 var$mailSubject="";//件名 var$m
13 Jun 2016
PHP メール送信の問題: メールは送信されましたが、無効なアドレスが返されました: 図に示すように: なぜこのようなことが起こるのでしょうか? ------解決策----------- public function AddAddress($address, $name = '') {&nb
18 Dec 2024
SMTP 認証経由で PHP で電子メールを送信するPHP では、SMTP サーバー経由で電子メールを送信するには、認証のための特定の設定が必要です。
ホットツール Tags
Hot Tools
依存関係注入コンテナー用の PHP ライブラリ
依存関係注入コンテナー用の PHP ライブラリ
50 個の優れた古典的な PHP アルゴリズムのコレクション
古典的な PHP アルゴリズム、優れたアイデアを学び、思考を広げます
画像を最適化するための小さな PHP ライブラリ
画像を最適化するための小さな PHP ライブラリ