I am not that great at php and am trying to learn. Anyway, I decided to make my own cms for my site and I have been working on the registration/login/activation part of it. I have a Amazon SES account I use for a forum I have up, so I was gonna use their same service for my site. Anyway, here is the php code.
[php]
function smtp_send_command($socket, $command, $response)
{
if(!empty($command)) fputs($socket, $command);
echo($command . ‘
’);
$smtp_response = ‘’;
while(substr($smtp_response, 3, 1) != ' ')
{
if(!($smtp_response = fgets($socket, 256)))
{
return false;
}
}
if($response === null) return substr($smtp_response, 0, 3);
if(substr($smtp_response, 0, 3) != $response) return false;
return true;
}
function send_smtp_mail($recipient, $recipient_name, $subject, $body)
{
global $mailSettings;
if($smtp_connect = fsockopen($mailSettings['host'], $mailSettings['port'], $errno, $errstr, $mailSettings['timeout']))
{
echo('connected<br />');
if(smtp_send_command($smtp_connect, null, '220'))
{
echo('attempting to say EHLO<br />');
if(smtp_send_command($smtp_connect, 'EHLO ' . $mailSettings['host'] . $mailSettings['newLine'], null) == '250')
{
echo('starting secure connection<br />');
smtp_send_command($smtp_connect, 'STARTTLS' . $mailSettings['newLine'], null);
stream_socket_enable_crypto($smtp_connect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
echo('attempting to request login<br />');
if(!smtp_send_command($smtp_connect, 'AUTH LOGIN' . $mailSettings['newLine'], '334')) return false;
//Send username
if(!smtp_send_command($smtp_connect, $mailSettings['user'] . $mailSettings['newLine'], '334')) return false;
//Send password
if(!smtp_send_command($smtp_connect, $mailSettings['pass'] . $mailSettings['newLine'], '235')) return false;
//Return Address
if(!smtp_send_command($smtp_connect, 'MAIL FROM: ' . $mailSettings['return'] . $mailSettings['newLine'], '250')) return false;
//Mail To
if(!smtp_send_command($smtp_connect, 'RCPT TO: ' . $recipient . $mailSettings['newLine'], '250')) return false;
//Email Start
if(!smtp_send_command($smtp_connect, 'DATA' . $mailSettings['newLine'], '354')) return false;
//Construct Headers
$headers = "MIME-Version: 1.0" . $mailSettings['newLine'];
$headers .= "Connect-Type: text/html; charset=iso-8859-1";
$headers .= "To: " . $recipient_name . " <" . $recipient . ">" . $mailSettings['newLine'];
$headers .= "From: my name <" . $mailSettings['return'] . ">" . $mailSettings['newLine'];
$headers .= "Subject: " . $subject . $mailSettings['newLine'];
$subject = str_replace('\n.', '\n..', $subject);
if(!smtp_send_command($smtp_connect, $headers . $mailSettings['newLine'] . $subject . '\n.\n', '250')) return false;
//Say bye
smtp_send_command($smtp_connect, 'QUIT' . $mailSettings['newLine'], null);
return true;
}
return false;
}
}
}
[/php]
and the $mailSettings array
[php]
$mailSettings = array(‘host’ => ‘email-smtp.us-east-1.amazonaws.com’,
‘port’ => ‘25’,
‘timeout’ => ‘3’,
‘identity’ => ‘…’,
‘newLine’ => ‘\r\n’,
‘user’ => ‘…’,
‘pass’ => ‘…’,
‘return’ => ‘noreply@mydoimain’);
[/php]
Anyway I have been tinkering with it for 3 days now, looking at some other systems, and am just stumped. If anyone sees anything I am not seeing right off that bat, that would be wonderful!