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.
<?php
/**
* Metoda wysyłająca wiadomość email.
*
* @return bool
*/
public function sendEmail()
{
if (!empty($this->sSmtpServer)) {
if ($rSmtpConnect = @fsockopen($this->sSmtpServer, $this->iPort, $iErrNo, $sErrStr, self::TimeOut)) {
$this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
);
@fputs($rSmtpConnect, "HELO " . self::Host . self::NewLine); $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
);
if ($this->bTLSSession)
{
@fputs($rSmtpConnect, "STARTTLS" . self::NewLine); $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
);
@fputs($rSmtpConnect, "HELO " . self::Host . self::NewLine); $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
); }
@fputs($rSmtpConnect, "AUTH LOGIN" . self::NewLine); $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
);
$this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
);
$this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
);
@fputs($rSmtpConnect, "MAIL FROM: " . $this->sFrom . self::NewLine); $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
);
@fputs($rSmtpConnect, "RCPT TO: " . $this->sTo . self::NewLine); $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
);
@fputs($rSmtpConnect, "DATA" . self::NewLine); $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
);
@fputs($rSmtpConnect, $this->sHeaders . self::NewLine); @fputs($rSmtpConnect, $this->sBody . self::NewLine); @fputs($rSmtpConnect, "." . self::NewLine); $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
);
@fputs($rSmtpConnect, "QUIT" . self::NewLine); $this->aSmtpResponse[] = @fgets($rSmtpConnect, 4096
); $bResult = substr($this->aSmtpResponse[9], 0, 3) == '221';
return $bResult;
}
return false;
}
else throw new MailerException('Nie ustawiono parametrów połączeniowych z serwerem !');
}
?>