J-H
J-H

Reputation: 1869

Php SMTP Mail sending works only local

I'm trying since hours now to get a mailscript working on a live server. It works as intended on my localhost.

I'm using exact the same external SMTP server, the same PHP sources and the same databasetables too. The PHP version and MySQL version online and localhost are identical.

I tested everything. Everything works as pretended without the physical sending process. It doesn't send (or receive) email. I also went to the systemadministrator to let him check if there are any emails blocked or internal server errors, but here also everything fine.

I really tried everything I could think of but I didn't find the problem. Has anybody an idea what I could try next?

This is how the function for the physical sending looks like:

private function sendPhysical($sReciepient) {
    if ($oSmtpIn = fsockopen(SMTPSERVER, SMTPPORT)) {
        fputs($oSmtpIn, "EHLO " . SMTPSERVER . "\r\n");
        $aCodes["hello"] = fgets($oSmtpIn, 1024);

        fputs($oSmtpIn, "auth login\r\n");
        $aCodes["res"] = fgets($oSmtpIn, 1024);

        fputs($oSmtpIn, $this->encodeUser() . "\r\n");
        $aCodes["user"] = fgets($oSmtpIn, 1024);

        fputs($oSmtpIn, $this->encodePassword() . "\r\n");
        $aCodes["pass"] = fgets($oSmtpIn, 256);

        fputs($oSmtpIn, "MAIL FROM: <" . $this->sFrom . ">\r\n");
        $aCodes["From"] = fgets($oSmtpIn, 1024);

        fputs($oSmtpIn, "RCPT TO: <" . $sReciepient . ">\r\n");
        $aCodes["To"] = fgets($oSmtpIn, 1024);

        fputs($oSmtpIn, "DATA\r\n");
        $aCodes["data"] = fgets($oSmtpIn, 1024);

        fputs($oSmtpIn, $this->generateHeader($sReciepient) . "\r\n\r\n" . $this->returnCompiledTemplate() . "\r\n.\r\n");
        $aCodes["send"] = fgets($oSmtpIn, 256);

        fputs($oSmtpIn, "QUIT\r\n");
        fclose($oSmtpIn);
    } else {
        $aCodes["connection"] = false;
    }
    return $aCodes;
}

Anybody a possible solution? I'm totally confused because it works at localhost and it already worked at the online server until last week...

Upvotes: 1

Views: 609

Answers (1)

kennycoder
kennycoder

Reputation: 56

It's quite tricky too see what's wrong on with this block of code but if you don't want to have much trouble sending mail via php, try PHPMailer.

Upvotes: 0

Related Questions