I’m using the script at the bottom of this to send authenticated email from a particular site.
I will be using this to send to a list of approx 2100 subscribers.
Two Questions.
QUESTION ONE
Testing with a single address, the email passes authentication and is sent as expected. However, looking at the headers of the test email I receive, I’m seeing:
“X-Comment: Sending client does not conform to RFC822 minimum requirements”
What is this, and is there a way to fix it or is it not a concern?
QUESTION TWO
To send to my list ( …and I’ve cleared with my host that I can send this many with certain constraints), I should simply loop my recordset thusly? (I usually do this in Coldfusion, and it works a little differently there…)
$rs->data_seek(0);
while($row = $rs->fetch_assoc()){
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $row['subscribed_address'], $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}
That looks like it’s opening/closing the connection for every single one of my 2100 emails. That sounds like a bad idea. Yes? No?
What’s “best practice” for this? Hopefully this isn’t too much of a noob question…
$SmtpServer="mail.mysite.com";
$SmtpPort="25"; //default
$SmtpUser="user@mysite.com";
$SmtpPass="mypassword";
class SMTPClient
{
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
{
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;
if ($SmtpPort == "") {
$this->PortSMTP = 25;
} else {
$this->PortSMTP = $SmtpPort;
}
}
function SendMail ()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
{
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\\r\
");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login\\r\
");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."\\r\
");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."\\r\
");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\\r\
");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\\r\
");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA\\r\
");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">\\r\
From: <".$this->from.">\\r\
Subject:".$this->subject."\\r\
\\r\
\\r\
".$this->body."\\r\
.\\r\
");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\\r\
");
fclose($SMTPIN);
//
}
return $talk;
}
}
if($_SERVER["REQUEST_METHOD"] == "POST") {
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['sub'];
$body = $_POST['message'];
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}