Il codice che utilizzo è il seguente (e non è neanche farina del mio sacco :-) )
$fp = fsockopen("smtp.pippo.it", 25, $errno, $errstr, 10);
$junk = fgets($fp, 512);
if(!$fp)
{
echo "Errore: $errstr($errno)";
}
else
{
// Mi presento al server SMTP
fputs($fp, "HELO smtp.pippo.it\r\n");
$junk = fgets($fp, 512);
// Imposto l'indirizzo del mittente
fputs($fp, "MAIL From: $IndirizzoMittente\r\n");
$junk = fgets($fp, 512);
// Imposto l'indirizzo del destinatario
fputs($fp, "RCPT TO: $IndirizzoDestinatario\r\n");
$junk = fgets($fp, 512);
// Inizia l'invio dei dati
fputs($fp, "DATA\r\n");
$junk = fgets($fp, 512);
// Indirizzo e nome del mittente
fputs($fp, "From: $NomeMittente<$IndirizzoMittente>\r\n");
// Indirizzo della eventuale risposta
fputs($fp, "Reply-To: $NomeMittente<$IndirizzoMittente>\r\n");
// Indirizzo e nome del destinatario
fputs($fp, "To: $NomeDestinatario<$IndirizzoDestinatario>\r\n");
// Oggetto della e-mail
fputs($fp, "Subject: $Oggetto\r\n");
// Testo della e-mail
fputs($fp, "\r\n");
fputs($fp, "$Dati\r\n");
// Fine del testo della e-mail
fputs($fp, ".\r\n");
$junk = fgets($fp, 512);
// Comunico al server SMTP che chiudo la sessione
fputs($fp, "QUIT\r\n");
$junk = fgets($fp, 512);
// Chiudo l'handle
fclose($fp);