Ciao a tutti dopo estenuanti ricerche ho trovato questo script e sembra funzionare.... pero a me nn piace vomitare righe di codice con copia incolla senza sapere assolutamente cosa sia...
Non c'e un modo molto piu semplice per inviare una banale email automatica?
Codice PHP:
$smtp_server = "smtp.miodominio.it"; # Il server SMTP a cui vogliamo collegarci
$port = "25"; # Porta del server...generalmente è la 25
$timeout = "30"; # Tempo di attesa per la risposta del server
$username = "mioindirizzo@miodominio.it"; # La vostra username
$password = "miapassword"; # La vostra password
$localhost = "localhost"; # Indirizzo dell'host ospitante
$newLine = "\r\n"; # Servirà per andare a capo nei comandi Telnet
$smtpConnect = fsockopen($smtp_server, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}
#Diciamo al server che vogliamo autenticarci
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
# Invio username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";
# Invio password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";
# Indico il mittente
fputs($smtpConnect, "MAIL FROM: $email" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";
# Indico il destinatario
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";
# Indico che ora voglio scrivere l'e-mail
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";
# Costruisco l'Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $to <$to>" . $newLine;
$headers .= "From: $nome $cognome <$email>" . $newLine;
# Invio l'e-mail
fputs($smtpConnect, "To: $to\nFrom: $email\nSubject: $subject\n$headers\n\n$body\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
?>