Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
2,502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. <?php
  2. //new function
  3.  
  4. $to = "lerenarzp2@gmail.com";
  5. $nameto = "Who To";
  6. $from = "postmaster@opigulf.com";
  7. $namefrom = "postmaster@domain.com";
  8. $subject = "Hello World Again!";
  9. $message = "World, Hello!";
  10. authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
  11. ?>
  12.  
  13.  
  14. <?php
  15. /* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */
  16.  
  17. //This will send an email using auth smtp and output a log array
  18. //logArray - connection,
  19.  
  20. function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
  21. {
  22. //SMTP + SERVER DETAILS
  23. /* * * * CONFIGURATION START * * * */
  24. $smtpServer = "mail.domain.com";
  25. $port = "587";
  26. $timeout = "30";
  27. $username = "postmaster@domain.com";
  28. $password = "Q1w2e3r4t5";
  29. $localhost = "mail.domain.com";
  30. $newLine = "\r\n";
  31. /* * * * CONFIGURATION END * * * * */
  32.  
  33. //Connect to the host on the specified port
  34. $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
  35. $smtpResponse = fgets($smtpConnect, 515);
  36. if(empty($smtpConnect))
  37. {
  38. $output = "Failed to connect: $smtpResponse";
  39. return $output;
  40. }
  41. else
  42. {
  43. $logArray['connection'] = "Connected: $smtpResponse";
  44. }
  45.  
  46. //Request Auth Login
  47. fputs($smtpConnect,"AUTH LOGIN" . $newLine);
  48. $smtpResponse = fgets($smtpConnect, 515);
  49. $logArray['authrequest'] = "$smtpResponse";
  50.  
  51. //Send username
  52. fputs($smtpConnect, base64_encode($username) . $newLine);
  53. $smtpResponse = fgets($smtpConnect, 515);
  54. $logArray['authusername'] = "$smtpResponse";
  55.  
  56. //Send password
  57. fputs($smtpConnect, base64_encode($password) . $newLine);
  58. $smtpResponse = fgets($smtpConnect, 515);
  59. $logArray['authpassword'] = "$smtpResponse";
  60.  
  61. //Say Hello to SMTP
  62. fputs($smtpConnect, "HELO $localhost" . $newLine);
  63. $smtpResponse = fgets($smtpConnect, 515);
  64. $logArray['heloresponse'] = "$smtpResponse";
  65.  
  66. //Email From
  67. fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
  68. $smtpResponse = fgets($smtpConnect, 515);
  69. $logArray['mailfromresponse'] = "$smtpResponse";
  70.  
  71. //Email To
  72. fputs($smtpConnect, "RCPT TO: $to" . $newLine);
  73. $smtpResponse = fgets($smtpConnect, 515);
  74. $logArray['mailtoresponse'] = "$smtpResponse";
  75.  
  76. //The Email
  77. fputs($smtpConnect, "DATA" . $newLine);
  78. $smtpResponse = fgets($smtpConnect, 515);
  79. $logArray['data1response'] = "$smtpResponse";
  80.  
  81. //Construct Headers
  82. $headers = "MIME-Version: 1.0" . $newLine;
  83. $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
  84. $headers .= "To: $nameto <$to>" . $newLine;
  85. $headers .= "From: $namefrom <$from>" . $newLine;
  86.  
  87. fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
  88. $smtpResponse = fgets($smtpConnect, 515);
  89. $logArray['data2response'] = "$smtpResponse";
  90.  
  91. // Say Bye to SMTP
  92. fputs($smtpConnect,"QUIT" . $newLine);
  93. $smtpResponse = fgets($smtpConnect, 515);
  94. $logArray['quitresponse'] = "$smtpResponse";
  95.  
  96. //insert var_dump here -- uncomment out the next line for debug info
  97. //var_dump($logArray);
  98. }
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement