検索
ホームページPHP ライブラリその他の図書館電子メールを送信するためのphpクラス
電子メールを送信するためのphpクラス

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

<?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); }elsereturn 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

関連記事

電子メールを送信するためのNetLify機能電子メールを送信するためのNetLify機能

21Apr2025

ジャムスタックスタイルのサイト(使用中のサーバー側の言語はありません)を揺らしていると言いましょうが、メールを送信するようなダイナミックなことをしたいと思います。ではありません

電子メールを検証するための正規表現ソリューション電子メールを検証するための正規表現ソリューション

13Jun2016

誰かが参照用に電子メール アドレスを確認するための正規表現を送ってくれませんか? 私が理解している電子メール ルール [email protected] /^[w-] @[w-] .[w-] $/ (これは機能しますか? ?)いくつかの特権メールボックスがありますが、それらを考慮する必要がありますか? QQ メールボックスは VIP メールボックス ドメイン名を開始しており、メンバーは排他的です。

PHPでSMTPを使用して電子メールを送信するためのコードPHPでSMTPを使用して電子メールを送信するためのコード

13Jun2016

php で SMTP を使用して電子メールを送信するためのコード。最近のプロジェクトでは、電子メールを送信するために SMTP が必要でした。以前のライブラリ クラスはもう存在しません。pear をインストールしたり、pear の net/smtp クラスを使用したりするのは面倒です。 discuz から直接抽出するだけです

PHPでsmtp経由で電子メールを送信するためのクラス、テストに合格しましたPHPでsmtp経由で電子メールを送信するためのクラス、テストに合格しました

13Jun2016

PHP で SMTP 経由で電子メールを送信するためのクラスはテストに合格しました。 smtp.php コードは次のとおりです。ユーザー;

詳細な手順を記載した電子メールを送信するためのフル機能の PHP コード詳細な手順を記載した電子メールを送信するためのフル機能の PHP コード

13Jun2016

詳細な手順を記載した電子メールを送信するためのフル機能の PHP コード。 ?php classEmail{ //---グローバル変数を設定します var$mailTo="";//受信者 var$mailCC="";//Cc var$mailBCC="";//シークレット Cc var$mailFrom =""; //送信者 var$mailSubject="";//件名 var$m

PHP での電子メール送信に関する問題: 電子メールは送信され、無効なアドレスが返されました。PHP での電子メール送信に関する問題: 電子メールは送信され、無効なアドレスが返されました。

13Jun2016

PHP メール送信の問題: メールは送信されましたが、無効なアドレスが返されました: 図に示すように: なぜこのようなことが起こるのでしょうか? ------解決策----------- public function AddAddress($address, $name = '') {&nb

See all articles