Autor Zpráva
drevokocur
Profil
Zdravím, zháňam php email skript s smtp authentifikáciou, ktorý bude odosielať cez cron pravidelné lokálne emaily. Jediné čo som doteraz zohnal, bol nasledujúci skript, ktorý ale nefunguje poriadne, vidím len v logoch na mail servery chybové hlášky (tiež uvádzam).

Kód email skriptu:

<?php  
//new function  
 
$to = "lolo@lolo.sk";  
$nameto = "lolo lolo";  
$from = "lolo@lolo.sk";  
$namefrom = "lolo";  
$subject = "Hello World Again!";  
$message = "World, Hello!";  
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);  
?>  
 
 
<?php  
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */   
 
//This will send an email using auth smtp and output a log array  
//logArray - connection,   
 
function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)  
{  
//SMTP + SERVER DETAILS  
/* * * * CONFIGURATION START * * * */ 
$smtpServer = "192.168.1.205";  
$port = "25";  
$timeout = "30";  
$username = "lolo@lolo.sk";  
$password = "lolo";  
$localhost = "192.168.1.205";  
$newLine = "\r\n";  
/* * * * 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";  
}  
 
//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);  
$logArray['authpassword'] = "$smtpResponse";  
 
//Say Hello to SMTP  
fputs($smtpConnect, "HELO $localhost" . $newLine);  
$smtpResponse = fgets($smtpConnect, 515);  
$logArray['heloresponse'] = "$smtpResponse";  
 
//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;  
 
fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");  
$smtpResponse = fgets($smtpConnect, 515);  
$logArray['data2response'] = "$smtpResponse";  
 
// Say Bye to SMTP  
fputs($smtpConnect,"QUIT" . $newLine);   
$smtpResponse = fgets($smtpConnect, 515);  
$logArray['quitresponse'] = "$smtpResponse";   

//insert var_dump here -- uncomment out the next line for debug info
//var_dump($logArray);
}  
?>  

Error na mail servery:

"SMTPD"    1844    244653    "2014-04-22 15:09:12.298"    "192.168.1.205"    "RECEIVED: DATA"
"SMTPD"    1844    244653    "2014-04-22 15:09:12.298"    "192.168.1.205"    "SENT: 503 Must have sender and recipient first."
"SMTPD"    1804    244653    "2014-04-22 15:09:12.314"    "192.168.1.205"    "RECEIVED: To: lolo@lolo.sk
From: lolo@lolo.sk
Subject: Hello World Again!
MIME-Version: 1.0"
"SMTPD"    1804    244653    "2014-04-22 15:09:12.314"    "192.168.1.205"    "SENT: 502 Unimplemented command."
"SMTPD"    1804    244653    "2014-04-22 15:09:12.314"    "192.168.1.205"    "RECEIVED: Content-type: text/html; charset=iso-8859-1"
"SMTPD"    1804    244653    "2014-04-22 15:09:12.314"    "192.168.1.205"    "SENT: 502 Unimplemented command."
"SMTPD"    1804    244653    "2014-04-22 15:09:12.314"    "192.168.1.205"    "RECEIVED: To: lolo lolo <lolo@lolo.sk>"
"SMTPD"    1804    244653    "2014-04-22 15:09:12.314"    "192.168.1.205"    "SENT: 502 Unimplemented command."
"SMTPD"    1804    244653    "2014-04-22 15:09:12.314"    "192.168.1.205"    "RECEIVED: From: lolo <lolo@lolo.sk>"
"SMTPD"    1804    244653    "2014-04-22 15:09:12.314"    "192.168.1.205"    "SENT: 502 Unimplemented command."
Taps
Profil
drevokocur:
nezkoušel jsi použít třídu phpmailer ?
drevokocur
Profil
Taps:
Zdravím, nie, nevyznám sa v tom absolútne, rád si nechám poradiť.
Radovan789
Profil *
http://hrazdil.info/blog/15-posilani-mailu-v-php-pomoci-phpmaileru

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: