Right...this is the all new & improved code:
Code: Select all
<?php
class mail
{
var $connection, $servers, $recipient, $sender, $log = array(), $user, $password;
function __construct($sender, $server = null, $user = null, $password = null)
{
list($this->sender['name'], $this->sender['domain']) = explode('@', $sender);
$this->user = $user;
$this->password = $password;
if($server != null)
$this->servers = (!is_array($server)) ? array($server) : $server;
else
{
getmxrr($this->sender['domain'], $this->servers, $server_weight);
if(is_array($this->servers))
array_multisort($this->servers, $server_weight);
}
}
public function send($recipient, $subject, $message)
{
if(!is_array($this->servers))
return false;
list($this->recipient['name'], $this->recipient['domain']) = explode('@', $recipient);
foreach($this->servers as $domain)
{
$this->connection = fsockopen($domain, 25);
if(!$this->connection)
continue;
if(!$this->_response(220))
continue;
$this->_send('EHLO '.$domain);
if(!$this->_response(220))
continue;
if(!in_array(null, array($this->user, $this->password)))
{
$this->_send('AUTH LOGIN');
if(!$this->_response(220))
continue;
$this->_send(base64_encode($this->user));
if(!$this->_response(250))
continue;
$this->_send(base64_encode($this->password));
if(!$this->_response(250))
continue;
}
$this->_send('MAIL FROM: <'.$this->sender['name'].'@'.$this->sender['domain'].'>');
if(!$this->_response(array(220, 250)))
continue;
$this->_send('RCPT TO: <'.$this->recipient['name'].'@'.$this->recipient['domain'].'>');
if(!$this->_response(250))
continue;
$this->_send('DATA');
if(!$this->_response(250))
continue;
$this->_send('To: '.$this->recipient['name'].'@'.$this->recipient['domain']);
$this->_send('From: '.$this->sender['name'].'@'.$this->sender['domain']);
$this->_send('Subject: '.$subject, true);
$this->_send(/*'Message: '.*/$message);
$this->_send('.');
$this->_send('QUIT');
return true;
break;
}
mail($recipient, $subject, $message, 'From:'.$this->sender['name'].'@'.$this->sender['domain']);
return false;
}
private function _send($message, $double_crlf = false)
{
array_push($this->log, $message);
fputs($this->connection, $message."\n".(($double_crlf) ? "\n" : null));
return true;
}
private function _response($response_code)
{
$response = fgets($this->connection);
array_push($this->log, $response);
$response_code = (!is_array($response_code)) ? array($response_code) : $response_code;
if(in_array(substr($response, 0, 3), $response_code))
return true;
else
return false;
}
}
?>
Ok, so sending to my gmail, I get this:
Array
(
[0] => 220-bumblebeeman.enixns.com ESMTP Exim 4.69 #1 Sun, 26 Jul 2009 01:38:51 +0100
[1] => EHLO jackpf.co.uk
[2] => 220-We do not authorize the use of this system to transport unsolicited,
[3] => AUTH LOGIN
[4] => 220 and/or bulk e-mail.
[5] => *base64_encod-ed username*
[6] => 250-bumblebeeman.enixns.com Hello cpc2-ipsw1-0-0-cust414.colc.cable.ntl.com [82.28.21.159]
[7] => *base64_encod-ed password*
[8] => 250-SIZE 52428800
[9] => MAIL FROM: <
webmaster@jackpf.co.uk>
[10] => 250-PIPELINING
[11] => RCPT TO: <
jack.philip.farrelly@gmail.com>
[12] => 250-AUTH PLAIN LOGIN
[13] => DATA
[14] => 250-STARTTLS
[15] => To:
jack.philip.farrelly@gmail.com
[16] => From:
webmaster@jackpf.co.uk
[17] => Subject: Subject
[18] => Message

[19] => .
[20] => QUIT
)
I've removed my smtp username and password, but apart from that, that's the entire transaction.
That works fine.
However, when sending that to a hotmail address, it either marks it as spam, or doesn't show up in either inbox or spam. It's ridiculous...I get all this facebook <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> but I can't send a proper email.
Any ideas how I can make this email look "real"?
Thanks for your help guys,
Jack.