Jump to content

Need help with a code


galford

Recommended Posts

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 = "broken@code.com";

$from = "test@test.com";

$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]

Link to comment
Share on other sites

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: test@test.com'  . $newLine);
fputs($smtpConnect, 'From: test@test.com' . $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;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.