Guarda...ho riscritto quasi completamente la funzione... Conteneva errori grossolani...
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */
//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,
function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message, $auth = 0)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "out.aliceposta.it";
$port = "25";
$timeout = "30";
$username = "user";
$password = "pass";
$localhost = "localhost";
$newLine = "\r\n";
$stato = 0;
/* * * * CONFIGURATION END * * * * */
//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}
//Say Hello to SMTP
fputs($smtpConnect, "EHLO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
do {
$smtpResponse = fgets($smtpConnect, 515);
} while(substr($smtpResponse, 3, 1) == "-");
$logArray['heloresponse'] = "$smtpResponse";
if($auth == 1)
{
//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";
//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
if(substr($smtpResponse, 0, 3) == "334");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
if(substr($smtpResponse, 0, 3) != "235")
{
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
fclose($smtpConnect);
return $stato;
}
}
//Email From
fputs($smtpConnect, "MAIL FROM:<$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";
//Email To
fputs($smtpConnect, "RCPT TO:<$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";
//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";
//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;
$headers .= "Subject: $subject" . $newLine;
fputs($smtpConnect, $headers.$newLine.$message.$newLine.".".$newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";
if(substr($smtpResponse, 0, 3) == "250")
$stato = 1;
// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
fclose($smtpConnect);
return $stato;
}
//con autenticazione
if(authSendEmail("
[email protected]", "Riccardo", "
[email protected]", "Pippo", "Ciao", "Ciccio", 1))
echo "La spedizione è andata a buon fine";
// senza autenticazione
//if(authSendEmail("
[email protected]", "Riccardo", "
[email protected]", "Pippo", "Ciao", "Ciccio", 0))
// echo "La spedizione è andata a buon fine";
?>