Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wysyłanie emaila + obsługa SSL
Jarod
post
Post #1





Grupa: Zarejestrowani
Postów: 1 190
Pomógł: 27
Dołączył: 23.04.2005

Ostrzeżenie: (0%)
-----


Napisałem sobie klasę do wysyłania emaili tekstowych. Wszystko pięknie działa, problem w tym, że jeśli serwer wymaga SSL (np. gmail) to nie działa. Przegrzebałem forum, google i nigdzie nie mogę znaleźć info, w którym miejscu popełniam błąd.
Może ktoś coś będzie mógł doradzić.

Metoda nawiązująca połączenie z serwerem i wysyłająca maila.
  1. <?php
  2. /**
  3.  * Metoda wysyłająca wiadomość email.
  4.  * 
  5.  * @return bool
  6.  */
  7. public function sendEmail()
  8. {
  9. if (!empty($this->sSmtpServer))
  10. {
  11. if ($rSmtpConnect = @fsockopen($this->sSmtpServer, $this->iPort, $iErrNo, $sErrStr, self::TimeOut))
  12. {
  13. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  14.  
  15. @fputs($rSmtpConnect, "HELO " . self::Host . self::NewLine);
  16. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  17.  
  18. if ($this->bTLSSession)
  19. {
  20. @fputs($rSmtpConnect, "STARTTLS" . self::NewLine);
  21. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  22.  
  23. @fputs($rSmtpConnect, "HELO " . self::Host . self::NewLine);
  24. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  25. }
  26.  
  27. @fputs($rSmtpConnect, "AUTH LOGIN" . self::NewLine);
  28. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  29.  
  30. @fputs($rSmtpConnect, base64_encode($this->sUsername) . self::NewLine);
  31. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  32.  
  33. @fputs($rSmtpConnect, base64_encode($this->sPassword) . self::NewLine);
  34. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  35.  
  36. @fputs($rSmtpConnect, "MAIL FROM: " . $this->sFrom . self::NewLine);
  37. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  38.  
  39. @fputs($rSmtpConnect, "RCPT TO: " . $this->sTo . self::NewLine);
  40. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  41.  
  42. @fputs($rSmtpConnect, "DATA" . self::NewLine);
  43. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  44.  
  45. @fputs($rSmtpConnect, $this->sHeaders . self::NewLine);
  46. @fputs($rSmtpConnect, $this->sBody . self::NewLine);
  47. @fputs($rSmtpConnect, "." . self::NewLine);
  48. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  49.  
  50. @fputs($rSmtpConnect, "QUIT" . self::NewLine);
  51. $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096);
  52. $bResult = substr($this->aSmtpResponse[9], 0, 3) == '221';
  53. @fclose($rSmtpConnect);
  54.  
  55. return $bResult;
  56. }
  57.  
  58. return false;
  59. }
  60. else throw new MailerException('Nie ustawiono parametrów połączeniowych z serwerem !');
  61. }
  62. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 11:04