Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. function authMail($from, $namefrom, $to, $nameto, $subject, $message)
  6. {
  7. /* your configuration here */
  8.  
  9. $smtpServer = "mail.wispi.ba";
  10. $port = "25";
  11. $timeout = "30";
  12. $username = "podrska@gamehosting.ba";
  13. $password = "azra666sisa";
  14. $localhost = "127.0.0.1";
  15. $newLine = "\r\n";
  16. $secure = 0;
  17.  
  18.  
  19.  
  20. //connect to the host and port
  21. $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
  22. $smtpResponse = fgets($smtpConnect, 4096);
  23. if(empty($smtpConnect))
  24. {
  25. $output = "Failed to connect: $smtpResponse";
  26. return $output;
  27. }
  28. else
  29. {
  30. $logArray['connection'] = "Connected to: $smtpResponse";
  31. }
  32.  
  33. //say HELO to our little friend
  34. fputs($smtpConnect, "HELO $localhost". $newLine);
  35. $smtpResponse = fgets($smtpConnect, 4096);
  36. $logArray['heloresponse'] = "$smtpResponse";
  37.  
  38. //start a tls session if needed
  39. if($secure)
  40. {
  41. fputs($smtpConnect, "STARTTLS". $newLine);
  42. $smtpResponse = fgets($smtpConnect, 4096);
  43. $logArray['tlsresponse'] = "$smtpResponse";
  44.  
  45. //you have to say HELO again after TLS is started
  46. fputs($smtpConnect, "HELO $localhost". $newLine);
  47. $smtpResponse = fgets($smtpConnect, 4096);
  48. $logArray['heloresponse2'] = "$smtpResponse";
  49. }
  50.  
  51. //request for auth login
  52. fputs($smtpConnect,"AUTH LOGIN" . $newLine);
  53. $smtpResponse = fgets($smtpConnect, 4096);
  54. $logArray['authrequest'] = "$smtpResponse";
  55.  
  56. //send the username
  57. fputs($smtpConnect, base64_encode($username) . $newLine);
  58. $smtpResponse = fgets($smtpConnect, 4096);
  59. $logArray['authusername'] = "$smtpResponse";
  60.  
  61. //send the password
  62. fputs($smtpConnect, base64_encode($password) . $newLine);
  63. $smtpResponse = fgets($smtpConnect, 4096);
  64. $logArray['authpassword'] = "$smtpResponse";
  65.  
  66. //email from
  67. fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
  68. $smtpResponse = fgets($smtpConnect, 4096);
  69. $logArray['mailfromresponse'] = "$smtpResponse";
  70.  
  71. //email to
  72. fputs($smtpConnect, "RCPT TO: $to" . $newLine);
  73. $smtpResponse = fgets($smtpConnect, 4096);
  74. $logArray['mailtoresponse'] = "$smtpResponse";
  75.  
  76. //the email
  77. fputs($smtpConnect, "DATA" . $newLine);
  78. $smtpResponse = fgets($smtpConnect, 4096);
  79. $logArray['data1response'] = "$smtpResponse";
  80.  
  81. //construct headers
  82. $headers = "MIME-Version: 1.0" . $newLine;
  83. $headers .= "Content-type: text/html; charset=windows-1250" . $newLine;
  84. $headers .= "To: $nameto <$to>" . $newLine;
  85. $headers .= "From: $namefrom <$from>" . $newLine;
  86.  
  87. //observe the . after the newline, it signals the end of message
  88. $poruka="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
  89. $poruka.="<HTML><HEAD>";
  90. $poruka.="<META http-equiv=3DContent-Type content=3D\"text/html; = charset=3Diso-8859-2\">";
  91. $poruka.="<META content=3D\"MSHTML 6.00.6000.16544\" name=3DGENERATOR>";
  92. $poruka.="<STYLE></STYLE>";
  93. $poruka.="</HEAD>";
  94. $poruka.="<BODY bgColor=3D#ffffff>";
  95. $poruka.="<DIV><FONT face=3DArial =size=3D2>".$message;
  96.  
  97.  
  98. $poruka.="</FONT></DIV></BODY></HTML>";
  99.  
  100.  
  101. fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
  102. $smtpResponse = fgets($smtpConnect, 4096);
  103. $logArray['data2response'] = "$smtpResponse";
  104.  
  105. // say goodbye
  106. fputs($smtpConnect,"QUIT" . $newLine);
  107. $smtpResponse = fgets($smtpConnect, 4096);
  108. $logArray['quitresponse'] = "$smtpResponse";
  109. $logArray['quitcode'] = substr($smtpResponse,0,3);
  110. fclose($smtpConnect);
  111. //a return value of 221 in $retVal["quitcode"] is a success
  112. return($logArray);
  113. }
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement