I'm trying to use the following code to send e-mails via SMTP, instead of using the mail() function (which works fine, so I can fall back on that).
// open socket
$stream = fsockopen($smtp_server, $port);
// send connection info
fputs($stream, "HELO $domain\r\n");
fputs($stream, "MAIL FROM:<$_POST[sender_email]>\r\n");
fputs($stream, "RCPT TO:<$email>\r\n");
// create headers and message
fputs($stream, "DATA\r\n");
fputs($stream, "From: \"$_POST[sender_forename] $_POST[sender_surname]\" <$_POST[sender_email]>\r\n");
fputs($stream, "To: $email\r\n");
fputs($stream, "Reply-to: <$_POST[sender_email]>\r\n");
fputs($stream, "Return-path: <$_POST[sender_email]>\r\n");
fputs($stream, "Subject: $_POST[subj]\r\n");
fputs($stream, "$msg\r\n");
fputs($stream, ".\r\n");
// close the connection
fputs($stream, "QUIT\r\n");
I know I'm not doing any authorisation, but even if I do insert the necessary lines, it still doesn't work.
Incidentally, it has worked before - once or twice - but since then it doesn't want to. I don't think there's anything wrong with the code - but maybe someone else has had similar behaviour, or can point out where the problem might lay.
Any ideas?