$this->delimiter = "\r\n";
function sendMessage($msg, $expectedResult = false)
{
if ($msg !== false && !empty($msg))
{
fputs($this->smtpSocket, $msg . "\r\n");
}
if ($expectedResult !== false)
{
$result = '';
while ($line = @fgets($this->smtpSocket, 1024))
{
$result .= $line;
if (preg_match('#^(\d{3}) #', $line, $matches))
{
break;
}
}
$this->smtpReturn = intval($matches[1]);
return ($this->smtpReturn == $expectedResult);
}
return true;
}
$this->smtpSocket = @fsockopen($this->smtpHost, $this->smtpPort, $errno, $errstr, 30);
$this->sendMessage("HELO smtp.qq.com",250);
$this->sendMessage("AUTH LOGIN",334);
$this->sendMessage(base64_encode($this->user),334);
$this->sendMessage(base64_encode($this->pass)."",235);
$this->sendMessage("MAIL FROM:<".$from.">",250);
$this->sendMessage("RCPT TO:<".$to.">",250);
$this->do_command("DATA",354);
日期
$this->sendMessage('Date: ' . gmdate('r'), false);
收件人
$this->sendMessage('To: ' . $this->toemail, false);
头部
$this->sendMessage(trim($this->headers), false); // trim to prevent double \r\n
标题
$this->sendMessage('Subject: ' . $this->subject, false);
// catch any single dots on their own
$this->message = preg_replace('#^.' . $this->delimiter . '#m', '..' . $this->delimiter, $this->message);
$this->sendMessage($this->message, false);
$this->sendMessage("\r\n.", 250)
$this->sendMessage('QUIT', 221);
加载更多