Guest User

Untitled

a guest
Dec 10th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. function authgMail($from, $namefrom, $to, $nameto, $subject, $message) {
  2. $smtpServer = "smtp.godisgrodan.se"; //ip address of the mail server. This can also be the local domain name
  3. $port = "25"; // should be 25 by default, but needs to be whichever port the mail server will be using for smtp
  4. $timeout = "45"; // typical timeout. try 45 for slow servers
  5. $username = "noreply@godisgrodan.se"; // the login for your smtp
  6. $password = "gotland123"; // the password for your smtp
  7. $localhost = "localhost"; // Defined for the web server. Since this is where we are gathering the details for the email
  8. $newLine = "\r\n"; // aka, carrage return line feed. var just for newlines in MS
  9. $secure = 0; // change to 1 if your server is running under SSL
  10.  
  11.  
  12. $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
  13. $smtpResponse = fgets($smtpConnect, 4096);
  14. if(empty($smtpConnect)) {
  15. $output = "Failed to connect: $smtpResponse";
  16. echo $output;
  17. return $output;
  18. }
  19. else {
  20. $logArray['connection'] = "<p>Connected to: $smtpResponse";
  21. echo "<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
  22. }
  23.  
  24. //you have to say HELO again after TLS is started
  25. fputs($smtpConnect, "HELO $localhost". $newLine);
  26. $smtpResponse = fgets($smtpConnect, 4096);
  27. $logArray['heloresponse2'] = "$smtpResponse";
  28. //request for auth login
  29. fputs($smtpConnect,"AUTH LOGIN" . $newLine);
  30. $smtpResponse = fgets($smtpConnect, 4096);
  31. $logArray['authrequest'] = "$smtpResponse";
  32.  
  33. //send the username
  34. fputs($smtpConnect, base64_encode($username) . $newLine);
  35. $smtpResponse = fgets($smtpConnect, 4096);
  36. $logArray['authusername'] = "$smtpResponse";
  37.  
  38. //send the password
  39. fputs($smtpConnect, base64_encode($password) . $newLine);
  40. $smtpResponse = fgets($smtpConnect, 4096);
  41. $logArray['authpassword'] = "$smtpResponse";
  42.  
  43. //email from
  44. fputs($smtpConnect, "MAIL FROM: <noreply@godisgrodan.se>" . $newLine);
  45. $smtpResponse = fgets($smtpConnect, 4096);
  46. $logArray['mailfromresponse'] = "$smtpResponse";
  47.  
  48. //email to
  49. fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
  50. $smtpResponse = fgets($smtpConnect, 4096);
  51. $logArray['mailtoresponse'] = "$smtpResponse";
  52.  
  53. //the email
  54. fputs($smtpConnect, "DATA" . $newLine);
  55. $smtpResponse = fgets($smtpConnect, 4096);
  56. $logArray['data1response'] = "$smtpResponse";
  57.  
  58. //construct headers
  59. $headers = "MIME-Version: 1.0" . $newLine;
  60. $headers .= "Content-type: text/html; charset=utf-8" . $newLine;
  61. $headers .= "To: Du <".$to.">" . $newLine;
  62. $headers .= "From: GodisGrodan.se <noreply@godisgrodan.se>" . $newLine;
  63.  
  64. //observe the . after the newline, it signals the end of message
  65. fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
  66. $smtpResponse = fgets($smtpConnect, 4096);
  67. $logArray['data2response'] = "$smtpResponse";
  68.  
  69. // say goodbye
  70. fputs($smtpConnect,"QUIT" . $newLine);
  71. $smtpResponse = fgets($smtpConnect, 4096);
  72. $logArray['quitresponse'] = "$smtpResponse";
  73. $logArray['quitcode'] = substr($smtpResponse,0,3);
  74. fclose($smtpConnect);
  75. //a return value of 221 in $retVal["quitcode"] is a success
  76. return($logArray);
  77. }
Add Comment
Please, Sign In to add comment