PHP Send e-mail class

Source: Internet
Author: User
Tags email account
  1. /***********************************************************************************
  2. Instructions for use:
  3. $m = new Sendm (' SMTP server address ', ' account ', ' Password ', port (int), timeout retry time (int));
  4. $m->send (' recipient mailbox ', ' Subject ', ' message body content ');
  5. Examples of Use:
  6. $m = new Sendm (' smtp.yeah.net ', ' testuser ', ' testuserpwd ', 25,30);
  7. $m->send (' a@coolmr.com ', ' Test mail ', ' This is a mail-sending class of test mail, thank you for your support ');
  8. *************************************************************************************/
  9. Class sendm{
  10. Private $Mailhost, $Mailuser, $Mailpwd, $Mailport, $Mailtimeout, $ms, $ending = "\ r \ n", $ENDINGC = "\ n";
  11. function __construct ($Mailhost, $Mailuser, $Mailpwd, $Mailport, $Mailtimeout) {
  12. $this->mailhost= $Mailhost;
  13. $this->mailuser= $Mailuser;
  14. $this->mailpwd= $Mailpwd;
  15. $this->mailport= $Mailport;
  16. $this->mailtimeout= $Mailtimeout;
  17. $this->connectsmtpserver ();
  18. }
  19. Private Function Connectsmtpserver () {
  20. if (!is_string ($this->mailhost)) {Settype (Trim ($this->mailhost), "string");}
  21. if (!is_integer ($this->mailport)) {Settype (Trim ($this->mailport), "Integer");}
  22. if (!is_integer ($this->mailtimeout)) {Settype (Trim ($this->mailtimeout), "Integer");}
  23. $this->ms= @fsockopen ($this->mailhost, $this->mailport, $this->errorno, $this->errorstr, $this Mailtimeout);
  24. if (substr (php_os,0,3)! = "WIN") {stream_set_timeout ($this->ms, $this->mailtimeout, 0);}
  25. $RCP = $this->get_echo ();
  26. Fputs ($this->ms, "Ehlo bobo". $this->ending);
  27. $RCP = $this->get_echo ();
  28. if (substr ($RCP, 0,3)! = ' + ') {return false;}
  29. Fputs ($this->ms, ' auth login '. $this->ending);
  30. $RCP = $this->get_echo ();
  31. if (substr ($RCP, 0,3) = = ' 334 ') {$this->auth ($this->mailuser, $this->mailpwd);} else{return false;}}
  32. Private Function Auth ($Mailuser, $Mailpwd) {
  33. $this->mailuseren=base64_encode ($Mailuser); $this->mailpwden=base64_encode ($MAILPWD);
  34. Fputs ($this->ms, $this->mailuseren. $this->ending);
  35. $RCP = $this->get_echo ();
  36. Fputs ($this->ms, $this->mailpwden. $this->ending);
  37. $RCP = $this->get_echo (); }
  38. Private Function Get_echo () {
  39. $edata = ""; while ($estr = @fgets ($this->ms,600)) {$edata. = $estr;
  40. if (substr ($estr, 3,1) = = "") {Break;}}
  41. return $edata; }
  42. Public Function Send ($to, $subject, $connect) {
  43. $host =explode ('. ', $this->mailhost);
  44. $fromaddress = $this->mailuser. ' @ '. $host [1]. '. '. $host [2];
  45. Fputs ($this->ms, ' Mail from:< '. $fromaddress. ' > '. $this->ending);
  46. $RCP = $this->get_echo ();
  47. Fputs ($this->ms, ' rcpt to:< '. $to. ' > '. $this->ending);
  48. $RCP = $this->get_echo ();
  49. Fputs ($this->ms, ' data '. $this->ending);
  50. $RCP = $this->get_echo ();
  51. Fputs ($this->ms, "to: $to". $this->ENDINGC);
  52. Fputs ($this->ms, "From: $fromaddress". $this->ENDINGC);
  53. Fputs ($this->ms, "Subject: $subject". $this->ENDINGC. $this->ENDINGC);
  54. Fputs ($this->ms, "$connect". $this->ENDINGC);
  55. Fputs ($this->ms, '. '. $this->ending);
  56. $RCP = $this->get_echo (); if (substr ($RCP, 0,3) = = ' + ') {header ("location:main_pro.php?act=msg&errors=on&msg= Mail sent successfully! Successfully submitted to the other server! "); } else{header ("location:main_pro.php?act=msg&errors=on&msg= very sorry, the Mail failed!" Please check the email account configuration is correct! "); }
  57. }
  58. }
  59. ?>
Copy Code
Send email, PHP
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.