Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. SMTPconfig.php
  2. You have to change SMTP server details.
  3. <?php
  4. //Server Address
  5. $SmtpServer="127.0.0.1";
  6. $SmtpPort="25"; //default
  7. $SmtpUser="username";
  8. $SmtpPass="password";
  9. ?>
  10.  
  11. SMTPclass.php
  12. SMTP mail sending class.
  13. <?php
  14. class SMTPClient
  15. {
  16.  
  17. function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
  18. {
  19.  
  20. $this->SmtpServer = $SmtpServer;
  21. $this->SmtpUser = base64_encode ($SmtpUser);
  22. $this->SmtpPass = base64_encode ($SmtpPass);
  23. $this->from = $from;
  24. $this->to = $to;
  25. $this->subject = $subject;
  26. $this->body = $body;
  27.  
  28. if ($SmtpPort == "")
  29. {
  30. $this->PortSMTP = 25;
  31. }
  32. else
  33. {
  34. $this->PortSMTP = $SmtpPort;
  35. }
  36. }
  37.  
  38. function SendMail ()
  39. {
  40. if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
  41. {
  42. fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n");
  43. $talk["hello"] = fgets ( $SMTPIN, 1024 );
  44. fputs($SMTPIN, "auth login\r\n");
  45. $talk["res"]=fgets($SMTPIN,1024);
  46. fputs($SMTPIN, $this->SmtpUser."\r\n");
  47. $talk["user"]=fgets($SMTPIN,1024);
  48. fputs($SMTPIN, $this->SmtpPass."\r\n");
  49. $talk["pass"]=fgets($SMTPIN,256);
  50. fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");
  51. $talk["From"] = fgets ( $SMTPIN, 1024 );
  52. fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");
  53. $talk["To"] = fgets ($SMTPIN, 1024);
  54. fputs($SMTPIN, "DATA\r\n");
  55. $talk["data"]=fgets( $SMTPIN,1024 );
  56. fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
  57. $talk["send"]=fgets($SMTPIN,256);
  58. //CLOSE CONNECTION AND EXIT ...
  59. fputs ($SMTPIN, "QUIT\r\n");
  60. fclose($SMTPIN);
  61. //
  62. }
  63. return $talk;
  64. }
  65. }
  66. ?>
  67.  
  68. index.php
  69. <?php
  70. include('SMTPconfig.php');
  71. include('SMTPClass.php');
  72. if($_SERVER["REQUEST_METHOD"] == "POST")
  73. {
  74. $to = $_POST['to'];
  75. $from = $_POST['from'];
  76. $subject = $_POST['sub'];
  77. $body = $_POST['message'];
  78. $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
  79. $SMTPChat = $SMTPMail->SendMail();
  80. }
  81. ?>
  82. <form method="post" action="">
  83. To:<input type="text" name="to" />
  84. From :<input type='text' name="from" />
  85. Subject :<input type='text' name="sub" />
  86. Message :<textarea name="message"></textarea>
  87. <input type="submit" value=" Send " />
  88. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement