galford Posted September 2, 2011 Share Posted September 2, 2011 Hello i'm working on a project and i've reach a dead end. What i'm trying to do with the code is this: 1. Connecting to an external smtp server; 2. Authenticating with login and pass using AUTH LOGIN using an external hostnames file (line-by-line), and external user and password file. 3. Send a email to a predefined email address on file using an external file with the email body. My problem is that I dont receive any email, what i'm guessing is that the auth login code is broken. Also I want to make a single user and password file using this format user:password. Also I want to make the code do this: to get the first smtp hostname and to login with the users:password in the external file provided. If unsuccessful login to try the next line in the users:password file. When finished with the login and password to jump to the next hostname in the hostname file. Here's my work so far: <?php function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message) { function loadini($path) { $fp = fopen($path, "r"); fclose($fp); } $message = loadini("message"); $to = "[email protected]"; $from = "[email protected]"; $namefrom = "test"; $subject = "test also"; $nameto = "notme"; authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); ?> //SMTP + SERVER DETAILS /* * * * CONFIGURATION START * * * */ $smtpServer = loadini("logfile");; $port = "25"; $timeout = "30"; $username = loadini("users"); $password = loadini("password"); $localhost = "localhost"; $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"; } //Say Hello to SMTP fputs($smtpConnect, "HELO $localhost" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['heloresponse'] = "$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"; //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"; } ?> I also attached a zip file with this. Thanks in advance. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/246251-need-help-with-a-code/ Share on other sites More sharing options...
gristoi Posted September 2, 2011 Share Posted September 2, 2011 without looking through all of your code i spotted this straight away. $smtpServer = loadini("logfile");; remove one of the semi colons Quote Link to comment https://forums.phpfreaks.com/topic/246251-need-help-with-a-code/#findComment-1264663 Share on other sites More sharing options...
galford Posted September 2, 2011 Author Share Posted September 2, 2011 I modified the code but the sintax is wrong... Can someone put me in the right direction? <?php //new function function loadini($path) { $fp = fopen($path, "r"); $fpcontents = fread($fp, filesize($path)); fclose($fp); return $fpcontents; } $subject = "Hello World Again!"; $message = loadini("message"); //SMTP + SERVER DETAILS /* * * * CONFIGURATION START * * * */ $smtpServer = loadini("logfile"); $port = "25"; $timeout = "30"; $username = loadini("users"); $password = loadini("password"); $localhost = "user"; $newLine = "\r\n"; /* * * * CONFIGURATION END * * * * */ //Connect to the host on the specified port $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout); $smtpResponse = fgets($smtpConnect, 515); echo 'Connection response was: ' . $smtpResponse; if(empty($smtpConnect)) { $output = "Failed to connect: $smtpResponse"; return $output; } else { $logArray['connection'] = "Connected: $smtpResponse"; } echo 'Response from connection attempt was: ' . $smtpResponse; //Say Hello to SMTP fputs($smtpConnect, "EHLO $localhost" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['heloresponse'] = "$smtpResponse"; echo 'Response from HELO was: ' . $smtpResponse; //Request Auth Login fputs($smtpConnect,"AUTH LOGIN" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authrequest'] = "$smtpResponse"; echo 'Response from AUTH LOGIN was: ' . $smtpResponse; //Send username fputs($smtpConnect, base64_encode($username) . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authusername'] = "$smtpResponse"; echo 'Response from USERNAME was: ' . $smtpResponse; //Send password fputs($smtpConnect, base64_encode($password) . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['authpassword'] = "$smtpResponse"; echo 'Response from PASSWORD was: ' . $smtpResponse; //The Email fputs($smtpConnect, 'DATA MIME-Version: 1.0' . $newLine); fputs($smtpConnect, 'Content-type: text/html; charset=iso-8859-1' . $newLine); fputs($smtpConnect, 'To: [email protected]' . $newLine); fputs($smtpConnect, 'From: [email protected]' . $newLine); fputs($smtpConnect, 'Subject: ' . $subject . $newLine . $newLine); fputs($smtpConnect, $message . $newLine); fputs($smtpConnect, '.' . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['data2response'] = "$smtpResponse"; echo 'Response from THE EMAIL was: ' . $smtpResponse; // Say Bye to SMTP fputs($smtpConnect,"QUIT" . $newLine); $smtpResponse = fgets($smtpConnect, 515); $logArray['quitresponse'] = "$smtpResponse"; echo 'Response from QUIT was: ' . $smtpResponse; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246251-need-help-with-a-code/#findComment-1264685 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.