I have two virtual private servers (VPS): one SMTP server on Windows Server 2008 R2 and the other is my website on CentOS. The problem is that when I try to send emails not all are sent: maybe two of eight, sometimes three. But when I host my website on my local machine and use fsockopen() it works perfectly.
Here's a sample:
Page 1:
<?php
include('SMTPconfig.php');
include('SMTPClass.php');
for ($i = 0; $i < 8; $i++) {
$SMTPMail = new SMTPClient ($serv, $port, $user, $pass, $from, $to, $header, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}
SMTPconfig.php:
<?php
$SmtpServer = "XXX.XXX.XXX.XXX";
$SmtpPort = "port";
$SmtpUser = "admin";
$SmtpPass = "****";
SMTPClass.php
<?php
class SMTPClient
{
function SMTPClient($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $a, $subject, $body)
{
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode($SmtpUser);
$this->SmtpPass = base64_encode($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->a = $a;
$this->subject = $subject;
$this->body = $body;
if ($SmtpPort == "") {
$this->PortSMTP = 25;
} else {
$this->PortSMTP = $SmtpPort;
}
}
function SendMail()
{
if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP, $errno, $errstr, 30)) {
fputs($SMTPIN, "EHLO " . $_SERVER['HTTP_HOST'] . "
");
$talk["hello"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "auth login
");
$talk["res"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpUser . "
");
$talk["user"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpPass . "
");
$talk["pass"] = fgets($SMTPIN, 256);
fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">
");
$talk["From"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "RCPT TO: <" . $this->to . ">
");
$talk["To"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "DATA
");
$talk["data"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->a . "
" . $this->body . "
.
");
$talk["send"] = fgets($SMTPIN, 256);
//CLOSE CONNECTION AND EXIT ...
fputs($SMTPIN, "QUIT
");
fclose($SMTPIN);
//
} else echo $errstr;
return $talk;
}
}
Please help! I've spent the past two days trying to find the problem but I can't find anything. Thank You!