Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's
Author Message
spyrule
Worker
Worker



Joined: Jun 06, 2006
Posts: 105

PostPosted: Tue Jun 13, 2006 11:03 pm Reply with quote

also,

my server is about to reboot, so if the script is not avail. wait 3 minutes and try again. (darn windows updates).

thx.
 
View user's profile Send private message Visit poster's website
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Tue Jun 13, 2006 11:37 pm Reply with quote

Any chance you can echo out this entire string?

"To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n"

Actually not even sure this is your final string anymore... I'd like to see what is being passed in the headers and message especially.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
spyrule







PostPosted: Wed Jun 14, 2006 8:08 am Reply with quote

ok,

so I added two echo's no echo formatting added , so you see what is sent :

Connection: Connected: 220 smtp101.rog.mail.re2.yahoo.com ESMTP .
Login: 334 VXNlcm5hbWU6 .
UID: 334 UGFzc3dvcmQ6 .
Password: 235 ok, go ahead (#2.0.0) .
HELO: 250 smtp101.rog.mail.re2.yahoo.com .
Mail From: 250 ok .
RCPT To: 250 ok .
data: 354 go ahead .
HEADERS: MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1 To: new member < [ Only registered users can see links on this board! Get registered or login! ] > From: tugeve <xxxxxxxx@tinytwo.net >

THE EMAIL: To: [ Only registered users can see links on this board! Get registered or login! ] From: [ Only registered users can see links on this board! Get registered or login! ] Subject: New User Account Activation MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1 To: new member < [ Only registered users can see links on this board! Get registered or login! ] > From: tugeve < [ Only registered users can see links on this board! Get registered or login! ] > ---- Welcome to [The Ultimate Gamers - TUGS] website! You or someone else has used your email account (xxxxxx@distributel.net) to register an account at [The Ultimate Gamers - TUGS] website. To finish the registration process you should visit the following link in the next 24 hours to activate your user account, otherwise the information will be automaticaly deleted by the system and you should apply again: eve.tugeve.net/modules.php?name=Your_Account&op=activate&username=spyrule3&check_num=acfe8a3d88da4a13ee4ac36687838c77 Following is the member information: -Nickname: xxxxxxxx -Password: xxxxxxxx . data2responce: 451 See [ Only registered users can see links on this board! Get registered or login! ] .
QUIT: .

I know this looks confusing, but yeah... i STILL don't see a bare LF...


Last edited by spyrule on Tue Jun 05, 2007 6:29 pm; edited 1 time in total 
spyrule







PostPosted: Wed Jun 14, 2006 9:32 am Reply with quote

ok,

well I figured out the problem.... it's nothing to do with the emails script itself. The actual problem was with the formatting of the actual message being sent.

here's the original line :

Code:



$message = ""._WELCOMETO." $sitename!\n\n"._YOUUSEDEMAIL." ($user_email) "._TOREGISTER." $sitename.\n\n "._TOFINISHUSER."\n\n $finishlink\n\n "._FOLLOWINGMEM."\n\n"._UNICKNAME." $username\n"._UPASSWORD." $user_password";



So I changed it to this, plus I added some formatting :
Code:


$message = "<center>"._WELCOMETO." $sitename!<br><br>\r\n\r\n"._YOUUSEDEMAIL." ($user_email) <br><br>"._TOREGISTER." $sitename.\r\n\r\n <br>"._TOFINISHUSER."\r\n\r\n <br><a href=$finishlink>$finishlink</a> <br><br>\r\n\r\n "._FOLLOWINGMEM."\r\n\r\n<br><br></center>"._UNICKNAME."<br><br> $username\r\n";


ok, and that fixed the problem. Now I have to edit all the other email functions to format the message correctly, but besides that... Basicly looks good to go for now.

Now I have one last major project, is to change the actual server that it is sending out through, and this is mainly because it seems to require different formatting. But it is not a priority task.

Thank you very much for your help... and if anybody needs help with setting up this kind of script, go to www . tugeve . net and email the admin, and I'll send you the script. I may even post a small tutorial on how to do what I just did.

Now, lets see if I can get the admin approval mod installed with this. Smile

Spyrule
 
spyrule







PostPosted: Wed Jun 14, 2006 9:34 am Reply with quote

You will also note in the changed code, I removed the password from being displayed. So that IF someone DID mis-type their email, the person on the far end will not get the password.

spyrule
 
montego







PostPosted: Thu Jun 15, 2006 7:04 am Reply with quote

Instead of changing all your code related to how your messages are formed, you may want to consider using a function like str_replace to ereg to just search for "bare" '\n' characters and replace with '\r\n'. You could potentially do this in the email function itself so that it is done only in one place.
 
spyrule







PostPosted: Thu Jun 15, 2006 7:32 am Reply with quote

I will be completely honest here...

I have NO IDEA... how to do that! Smile

spyrule.
 
banelos
Hangin' Around



Joined: May 05, 2006
Posts: 30

PostPosted: Thu Jun 15, 2006 10:31 pm Reply with quote

Ok this is exactly what I've been looking for in order to solve the problem I've asked for help about on this thread.

I've been testing this to see if I could just get the test script to work on my server but I get this msg when execution the script (with the echo part near auth login)
"Login: 220-We do not authorize the use of this system to transport unsolicited."
Is it a problem with my login details? cause I've tried several different that I currently use on the bbtonuke board, which work so shouldnt be that.

Also I've been wondering.. Wouldnt it be better to change all the mail() functions in Your_Account to use the smtpmail() function found in includes/smtp.php ?
Been trying to do a test where I include includes/smtp.php in a test script, but when I run it all I get is "Fatal error: Call to undefined function: message_die() in <etc.>/smtp.php on line 113"

Would really like to see a working Your_Account/index.php that uses smtpmail instead of the normal mail() function Smile

Thanks in advance!
 
View user's profile Send private message
montego







PostPosted: Fri Jun 16, 2006 12:17 am Reply with quote

montego wrote:
Instead of changing all your code related to how your messages are formed, you may want to consider using a function like str_replace to ereg to just search for "bare" '\n' characters and replace with '\r\n'. You could potentially do this in the email function itself so that it is done only in one place.


Have not tested this, but I wonder if this would work:

$message = str_replace('\n', '\r\n', $message);

It that does not work, maybe:

$message = str_replace('\\n', '\\r\\n', $message);
 
montego







PostPosted: Fri Jun 16, 2006 12:17 am Reply with quote

Quote:

Would really like to see a working Your_Account/index.php that uses smtpmail instead of the normal mail() function


Maybe spyrule would be willing to email it to you?
 
spyrule







PostPosted: Wed Jun 21, 2006 7:27 am Reply with quote

Copy and past the following code into a file called "authSendMail.php"
Then save the file to the /includes/ folder.
Code:


/* START COPY HERE */
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,


// To test the OUTPUT of this script to your screen, uncomment the ECHO commands.
// echo commands are on lines: 47, 54, 60, 66, 72, 78, 84, 90, 97, 103 and 105

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{

   /* * * * CONFIGURATION START * * * */

   /* Change the following lines to reflect your smtp server settings */

   $smtpServer = "your outgoing smtp server.com";
   $port = "25";
   $timeout = "60";
   $username = "xxxxxxxx@smtpserver.com";
   $password = "xxxxxxxx";

   $localhost = "YOURWEBSITE.COM";
   $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";
       echo "$output .";
       return $output;
   }
   else
   {
       $logArray['connection'] = "Connected: $smtpResponse";

//echo "<br>CONNECTION: ".$logArray['connection']." ";

   }

   /* Request Auth Login */
   fputs($smtpConnect,"HELO AUTH LOGIN" . $newLine);
   $smtpResponse = fgets($smtpConnect, 515);
   $logArray['authrequest'] = "$smtpResponse";

//echo "<br>AUTH LOGIN: ".$logArray['authrequest']."";


   /* Send username */
   fputs($smtpConnect, base64_encode($username) . $newLine);
   $smtpResponse = fgets($smtpConnect, 515);
   $logArray['authusername'] = "$smtpResponse";

//echo "<br>UID: ".$logArray['authusername']."";


   /* Send password */
   fputs($smtpConnect, base64_encode($password) . $newLine);
   $smtpResponse = fgets($smtpConnect, 515);
   $logArray['authpassword'] = "$smtpResponse";

//echo "<br>PASSWORD: ".$logArray['authpassword']."";


   /* Say Hello to SMTP */
   fputs($smtpConnect, "HELO $localhost" . $newLine);
   $smtpResponse = fgets($smtpConnect, 515);
   $logArray['heloresponse'] = "$smtpResponse";

//echo "<br>HELO: ".$logArray['heloresponse']."";


   /* Email From */
   fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
   $smtpResponse = fgets($smtpConnect, 515);
   $logArray['mailfromresponse'] = "$smtpResponse";

//echo "<br>MAIL FROM: ".$logArray['mailfromresponse']."";


   /* Email To */
   fputs($smtpConnect, "RCPT TO: $to" . $newLine);
   $smtpResponse = fgets($smtpConnect, 515);
   $logArray['mailtoresponse'] = "$smtpResponse";

//echo "<br>RCPT TO: ".$logArray['mailtoresponse']."";


   /* The Email */
   fputs($smtpConnect, "DATA" . $newLine);
   $smtpResponse = fgets($smtpConnect, 515);
   $logArray['data1response'] = "$smtpResponse";

//echo "<br>DATA: ".$logArray['data1response']."";


   /* Construct Headers */
   $headers  = "MIME-Version: 1.0" . $newLine;
   $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
   // The following 2 line were commented out, otherwise you get double to/from fields under phpnuke.
   // $headers .= "To: $to" . $newLine;
   // $headers .= "From: $from" . $newLine;

//echo "<br>HEADERS: $headers";

   /* Fix all messages to have proper <CR> returns for all SMTP messages. */
   $message = str_replace("\n", "\r\n", $message);

   fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n$message\r\n.\r\n");
   $smtpResponse = fgets($smtpConnect, 515);
   $logArray['data2response'] = "$smtpResponse";


//echo "<br>THE EMAIL:<br> To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n$message\r\n.\r\n";
//echo "<br>DATA2RESPONCE: ".$logArray['data2response']."........ = If this reads '250 ok ...' then the message was sent.";


   /* Say Bye to SMTP */
   fputs($smtpConnect,"QUIT" . $newLine);
   $smtpResponse = fgets($smtpConnect, 515);
   $logArray['quitresponse'] = "$smtpResponse";

//echo "<br>QUIT: ".$logArray['quitresponse']."";

}
?>

/* STOP COPY HERE */

 Then for testing purposes, I suggest that you uncomment (remove the two //'s) from the
 //echo "..."; commands.  This will output each step of the communication that you get
 from your smtp provider. VERY useful for determining the issues.

 Then, again for testing purposes, only make the change in one file at first.
 go to your /modules/Your_Account/index.php file.

  Add this right after the comments section right near the top of the file:

 include_once('includes/authSendEmail.php');

 Do a search in the file for "mail(" you will find 4-5 in total. 

 The first two, that is something like "..._mail()" IGNORE IT, DO NOT MODIFY THOSE LINES. 
 The ONLY lines you need to modify are something like :

 mail($user_email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());

 I suggest that you comment out the entire line and create a new one just underneath it
 with the replacement authSendMail(); command.

 Now the authSendMail command has 2 fields that are not normally used by phpnuke:
 $namefrom and $nameto fields.  From what I can tell, their is no equivalent field.

 so I replace them with the intended message to be sent, so for password update, I put just that.

 So example, from the above mail() line:

 mail($user_email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());

 replace with:

 authSendMail($from, 'YOURWEBSITE.COM', $user_email, '-', $subject, $message);

 The trick here is to match up the fields in the proper order of the new function.
 Here is the perameter order of the authSendMail function :

 $from, $namefrom, $to, $nameto, $subject, $message.

 Then with that, create a new registration, and submit it. You should get the responce right away,
 on the screen. It will output each step that the script performs (providing you uncommented the
 echo commands).

 If the output ends in a line something like "250 ..." it means it was sent succesfully.
 Any other errors, at that point, it will at least tell you where the problem is and better
 direct you to a fix.

Now I know this script WILL NOT work with certain types of SMTP servers. Why... I don't honestly
know. I'm still trying to get it to work with those servers.

I will be posting an update when I have suceeded in making the script work with a broader range of
smtp servers. So far, an smtp server that I KNOW won't work is NO-IP.com's forwarding smtp service.
however, my current ISP (rogers.com), DOES work.

Hope this helps some,

Spyrule.
 
banelos







PostPosted: Wed Jun 21, 2006 10:26 am Reply with quote

Yay I got this to work on my server with the help of the server admin (thanks Ben if you see this post).

Problem for me with this was that the script was only expecting 1 line of answer from the server on connect and on auth.. The server admin changed the script for me so it accepted 2 more lines in the connect to the host, and 5 more lines in the "Request Auth Login" part of the script. Also he changed the auth code line to use EHLO instead of HELO, which also seemed to work better for the auth part.

Posting the complete authSendMail.php that worked for me here in case it helps anyone else wanting to fix this problem. It needs to be put in the "includes" folder for the testmail.php script and the changes in Your_Account module to work

This one is with all the echos in to test if the function work
Code:


<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,


// To test the OUTPUT of this script to your screen, uncomment the ECHO commands.
// echo commands are on lines: 47, 54, 60, 66, 72, 78, 84, 90, 97, 103 and 105

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{

/* * * * CONFIGURATION START * * * */

/* Change the following lines to reflect your smtp server settings */

$smtpServer = "your outgoing smtp server.com";
$port = "25";
$timeout = "60";
$username = "xxxxxxxx@smtpserver.com";
$password = "xxxxxxxx";

$localhost = "YOURWEBSITE.COM";
$newLine = "\r\n";

/* * * * CONFIGURATION END * * * * */

/* Connect to the host on the specified port */
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse .= fgets($smtpConnect, 515);
$smtpResponse .= fgets($smtpConnect, 515);

if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
echo "$output .";
return $output;
}
else
{

$logArray['connection'] = "Connected: $smtpResponse";

echo "<br>CONNECTION: ".$logArray['connection']." ";

}

/* Request Auth Login */
fputs($smtpConnect,"EHLO" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse = fgets($smtpConnect, 515);


fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";

echo "<br>AUTH LOGIN: ".$logArray['authrequest']."";


/* Send username */
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";

echo "<br>UID: ".$logArray['authusername']."";


/* Send password */
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";

//echo "<br>PASSWORD: ".$logArray['authpassword']."";


/* Say Hello to SMTP */
// fputs($smtpConnect, "HELO $localhost" . $newLine);
// $smtpResponse = fgets($smtpConnect, 515);
// $logArray['heloresponse'] = "$smtpResponse";

// echo "<br>HELO: ".$logArray['heloresponse']."";


/* Email From */
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

echo "<br>MAIL FROM: ".$logArray['mailfromresponse']."";


/* Email To */
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";

echo "<br>RCPT TO: ".$logArray['mailtoresponse']."";


/* The Email */
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";

echo "<br>DATA: ".$logArray['data1response']."";


/* Construct Headers */
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
// The following 2 line were commented out, otherwise you get double to/from fields under phpnuke.
// $headers .= "To: $to" . $newLine;
// $headers .= "From: $from" . $newLine;

echo "<br>HEADERS: $headers";

/* Fix all messages to have proper <CR> returns for all SMTP messages. */
$message = str_replace("\n", "\r\n", $message);

fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";


echo "<br>THE EMAIL:<br> To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n$message\r\n.\r\n";
echo "<br>DATA2RESPONCE: ".$logArray['data2response']."........ = If this reads '250 ok ...' then the message was sent.";


/* Say Bye to SMTP */
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";

echo "<br>QUIT: ".$logArray['quitresponse']."";

}
?>


That was with all Echos on for all but the password command.

Here is the exact code for authSendMail.php without any echo:
Code:


<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,


// To test the OUTPUT of this script to your screen, uncomment the ECHO commands.
// echo commands are on lines: 47, 54, 60, 66, 72, 78, 84, 90, 97, 103 and 105

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{

/* * * * CONFIGURATION START * * * */

/* Change the following lines to reflect your smtp server settings */

$smtpServer = "your outgoing smtp server.com";
$port = "25";
$timeout = "60";
$username = "xxxxxxxx@smtpserver.com";
$password = "xxxxxxxx";

$localhost = "YOURWEBSITE.COM";
$newLine = "\r\n";

/* * * * CONFIGURATION END * * * * */

/* Connect to the host on the specified port */
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse .= fgets($smtpConnect, 515);
$smtpResponse .= fgets($smtpConnect, 515);

if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
echo "$output .";
return $output;
}
else
{

$logArray['connection'] = "Connected: $smtpResponse";

//echo "<br>CONNECTION: ".$logArray['connection']." ";

}

/* Request Auth Login */
fputs($smtpConnect,"EHLO" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse = fgets($smtpConnect, 515);
$smtpResponse = fgets($smtpConnect, 515);


fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";

//echo "<br>AUTH LOGIN: ".$logArray['authrequest']."";


/* Send username */
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";

//echo "<br>UID: ".$logArray['authusername']."";


/* Send password */
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";

//echo "<br>PASSWORD: ".$logArray['authpassword']."";


/* Say Hello to SMTP */
// fputs($smtpConnect, "HELO $localhost" . $newLine);
// $smtpResponse = fgets($smtpConnect, 515);
// $logArray['heloresponse'] = "$smtpResponse";

// echo "<br>HELO: ".$logArray['heloresponse']."";


/* Email From */
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

//echo "<br>MAIL FROM: ".$logArray['mailfromresponse']."";


/* Email To */
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";

//echo "<br>RCPT TO: ".$logArray['mailtoresponse']."";


/* The Email */
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";

//echo "<br>DATA: ".$logArray['data1response']."";


/* Construct Headers */
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
// The following 2 line were commented out, otherwise you get double to/from fields under phpnuke.
// $headers .= "To: $to" . $newLine;
// $headers .= "From: $from" . $newLine;

//echo "<br>HEADERS: $headers";

/* Fix all messages to have proper <CR> returns for all SMTP messages. */
$message = str_replace("\n", "\r\n", $message);

fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";


//echo "<br>THE EMAIL:<br> To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n$message\r\n.\r\n";
//echo "<br>DATA2RESPONCE: ".$logArray['data2response']."........ = If this reads '250 ok ...' then the message was sent.";


/* Say Bye to SMTP */
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";

//echo "<br>QUIT: ".$logArray['quitresponse']."";

}
?>


You don't need to edit the index.php in the modules/Your_Account to test it either..

I simply made a testmail.php file with the following code to test it, and uploaded it to the root of my website, while having the authSendMail.php in the includes folder.
Code:


<?php
//new function
include_once('includes/authSendMail.php');
$user_email = "to@email.com";
$from = "your@email.com";  //Needs a valid email address
$subject = "TestEmail";
$message = "HelloWorld";
authSendEmail($from, 'YOURSITE.COM', $user_email, '-', $subject, $message);
?>
 
montego







PostPosted: Thu Jun 22, 2006 5:38 am Reply with quote

I hope you all do not mind, but this is such good information, I have made this a "Sticky" post and have moved it under the "How To" forum!
 
spyrule







PostPosted: Thu Jun 22, 2006 12:42 pm Reply with quote

unfortunately,

I tried the above code with another smtp server, and all I ever got was server
timed out after 30 seconds.

even with a little modification, it didn't seem to work, so it maybe smtp server
specific.

If anything banalos, if you could find out what kind of smtp server (smtp helo
responce), so that anybody else using the same kind will know .

Thanks for the info as well.

Spyrule
 
marcelolaia
Hangin' Around



Joined: Sep 28, 2005
Posts: 36
Location: Brazil

PostPosted: Wed Aug 30, 2006 5:33 am Reply with quote

I did a test im my server and I get this log:

Quote:
CONNECTION: Connected: 220 jaragua.myserver.com ESMTP Postfix
AUTH LOGIN: 502 5.5.2 Error: command not recognized
UID: 502 5.5.2 Error: command not recognized
MAIL FROM: 503 5.5.1 Error: send HELO/EHLO first
RCPT TO: 503 5.5.1 Error: need MAIL command
DATA: 503 5.5.1 Error: need RCPT command
HEADERS: MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1
THE EMAIL:
To: [ Only registered users can see links on this board! Get registered or login! ] From: [ Only registered users can see links on this board! Get registered or login! ] Subject: TestEmail MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1 HelloWorld .
DATA2RESPONCE: 221 2.7.0 Error: I can break rules, too. Goodbye. ........ = If this reads '250 ok ...' then the message was sent.
QUIT:


And the message was not send

I no need a password to send message in my smtp server, then, I leave this field empty in authSendMail.php.

Any suggestion?

Thank you

_________________
Marcelo [ Only registered users can see links on this board! Get registered or login! ]
O site do Pós-Graduando
Concurso, Notícias, CAPES, CNPq, FAPESP, Mestrado, Doutorado, Professor, Público, Universidade, Faculdade 
View user's profile Send private message Visit poster's website
banelos







PostPosted: Fri Sep 15, 2006 3:55 am Reply with quote

Ok just a short update on this subject.

Since what have been giving most of us trouble with the standard mail() function is our host having this function disabled and we needed to make our own custom function to send mails using our smtp server.

But I think this new admin module made by Slaytanic and featured on the frontpage called "PhpNukeMailer" should be able to do the trick for most people now instead of using the method me and Spyrule used.

The PHPNukeMailer module can be downloaded from http://prdownloads.sourceforge.net/slaytanic/, currently the newest version of it seems to be 1.0.7

The function reads:
phpnukemail($recipient, $subject, $body, $from, $fromname, $encode=0, $cc=NULL, $bcc=NULL, $attachment=NULL)

So at a quick glance I think the only thing you need to do to make this module work with Your_Account module is to:

Open modules/Your_Account/index.php and FIND the 3 instances of:
Code:
mail($user_email, $subject, $message, "From: $adminmail\nX-Mailer: PHP/" . phpversion());


The first one has a slight difference in the from part and looks like this:
Code:
mail($user_email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());


and REPLACE each of these 3 lines with the following code:
Code:
phpnukemail($user_email, $subject, $message, $adminmail, $sitename);


Havn't really had the chance to test this yet, but if the PHPNukeMailer modules is installed and you have set up the SMTP login under the admin part (located in main admin section) I don't see why it shouldn't work. Will update on it once I get a chance to try it out.
 
marcelolaia







PostPosted: Fri Sep 15, 2006 8:25 am Reply with quote

Hi,

smtp_port INT(10) NOT NULL default '' in pnm_setup.php must be set up to a valid interger. Otherwise, the script dosent create the tables.

Thank you
 
themadhacker
Worker
Worker



Joined: May 30, 2006
Posts: 100

PostPosted: Wed Sep 27, 2006 2:51 pm Reply with quote

I have tested the authSendMail.php with the individual testMail.php file. Works fine.

However I cant get it to work with phpNuke.

What I am doing is running ravens phpNuke with Apache2Triad. I am using this for a LAN intranet site so I really only need SMTP to work as no one will ever get any incoming emails on he private domain.

Any updates is appreciated.
 
View user's profile Send private message
themadhacker







PostPosted: Thu Sep 28, 2006 11:13 am Reply with quote

spyrule wrote:
Copy and past the following code into a file called "authSendMail.php"
Then save the file to the /includes/ folder.

/* START COPY HERE */
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,


// To test the OUTPUT of this script to your screen, uncomment the ECHO commands.
// echo commands are on lines: 47, 54, 60, 66, 72, 78, 84, 90, 97, 103 and 105

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{

/* * * * CONFIGURATION START * * * */

/* Change the following lines to reflect your smtp server settings */

$smtpServer = "your outgoing smtp server.com";
$port = "25";
$timeout = "60";
$username = "xxxxxxxx@smtpserver.com";
$password = "xxxxxxxx";

$localhost = "YOURWEBSITE.COM";
$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";
echo "$output .";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";

//echo "<br>CONNECTION: ".$logArray['connection']." ";

}

/* Request Auth Login */
fputs($smtpConnect,"HELO AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";

//echo "<br>AUTH LOGIN: ".$logArray['authrequest']."";


/* Send username */
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";

//echo "<br>UID: ".$logArray['authusername']."";


/* Send password */
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";

//echo "<br>PASSWORD: ".$logArray['authpassword']."";


/* Say Hello to SMTP */
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";

//echo "<br>HELO: ".$logArray['heloresponse']."";


/* Email From */
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

//echo "<br>MAIL FROM: ".$logArray['mailfromresponse']."";


/* Email To */
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";

//echo "<br>RCPT TO: ".$logArray['mailtoresponse']."";


/* The Email */
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";

//echo "<br>DATA: ".$logArray['data1response']."";


/* Construct Headers */
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
// The following 2 line were commented out, otherwise you get double to/from fields under phpnuke.
// $headers .= "To: $to" . $newLine;
// $headers .= "From: $from" . $newLine;

//echo "<br>HEADERS: $headers";

/* Fix all messages to have proper <CR> returns for all SMTP messages. */
$message = str_replace("\n", "\r\n", $message);

fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";


//echo "<br>THE EMAIL:<br> To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n$message\r\n.\r\n";
//echo "<br>DATA2RESPONCE: ".$logArray['data2response']."........ = If this reads '250 ok ...' then the message was sent.";


/* Say Bye to SMTP */
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";

//echo "<br>QUIT: ".$logArray['quitresponse']."";

}
?>

/* STOP COPY HERE */

Then for testing purposes, I suggest that you uncomment (remove the two //'s) from the
//echo "..."; commands. This will output each step of the communication that you get
from your smtp provider. VERY useful for determining the issues.

Then, again for testing purposes, only make the change in one file at first.
go to your /modules/Your_Account/index.php file.

Add this right after the comments section right near the top of the file:

include_once('includes/authSendEmail.php');

Do a search in the file for "mail(" you will find 4-5 in total.

The first two, that is something like "..._mail()" IGNORE IT, DO NOT MODIFY THOSE LINES.
The ONLY lines you need to modify are something like :

mail($user_email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());

I suggest that you comment out the entire line and create a new one just underneath it
with the replacement authSendMail(); command.

Now the authSendMail command has 2 fields that are not normally used by phpnuke:
$namefrom and $nameto fields. From what I can tell, their is no equivalent field.

so I replace them with the intended message to be sent, so for password update, I put just that.

So example, from the above mail() line:

mail($user_email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());

replace with:

authSendMail($from, 'YOURWEBSITE.COM', $user_email, '-', $subject, $message);

The trick here is to match up the fields in the proper order of the new function.
Here is the perameter order of the authSendMail function :

$from, $namefrom, $to, $nameto, $subject, $message.

Then with that, create a new registration, and submit it. You should get the responce right away,
on the screen. It will output each step that the script performs (providing you uncommented the
echo commands).

If the output ends in a line something like "250 ..." it means it was sent succesfully.
Any other errors, at that point, it will at least tell you where the problem is and better
direct you to a fix.

Now I know this script WILL NOT work with certain types of SMTP servers. Why... I don't honestly
know. I'm still trying to get it to work with those servers.

I will be posting an update when I have suceeded in making the script work with a broader range of
smtp servers. So far, an smtp server that I KNOW won't work is NO-IP.com's forwarding smtp service.
however, my current ISP (rogers.com), DOES work.

Hope this helps some,

Spyrule.


I finally figured out why I couldnt get this to work with phpNuke. I would think everyone that used this would have this same problem if going with the function call mentioned in the above quoted post.

The post above references this...

Code:


authSendMail($from, 'YOURSERVER.COM', $user_email, '-', $subject, $message);


when it should be this...
Code:


authSendEmail($from, 'YOURSERVER.COM', $user_email, '-', $subject, $message);


I didnt think to turn debug on in config.php because it worked with the testmail.php file. So everyone should consider debugging their friend! LOL

Anyway...just wanted to correct this thread in order to save some people a little time figureing this out.

Great work on the script to everyone who contributed. It works like a champ....and since I am using phpNuke for a LAN site...this fix will make the email function work just like the site is running on a WAN.

Thanks everyone Very Happy
 
runswithscissors
Hangin' Around



Joined: Aug 16, 2006
Posts: 40

PostPosted: Wed Oct 25, 2006 3:16 pm Reply with quote

so did anyone ever actually get this to work?
What the hell happend here the thread just died?
 
View user's profile Send private message
runswithscissors







PostPosted: Wed Oct 25, 2006 3:31 pm Reply with quote

What happend here the thread just stops with no resolution.
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Wed Oct 25, 2006 3:59 pm Reply with quote

We can't solve world hunger. We do what we can.
 
View user's profile Send private message
montego







PostPosted: Thu Oct 26, 2006 6:06 am Reply with quote

runswithscissors, sometimes we have to reply solely on the contributions of the community. I can personally say that I have NEVER had to make nuke work with SMTP. My preference is to work with a host who provides the services that I need. If its a PHP-Nuke friendly service you need...
 
montego







PostPosted: Thu Oct 26, 2006 6:34 am Reply with quote

Well, just saw this thread: [ Only registered users can see links on this board! Get registered or login! ]

Thought maybe the "cross-link" would be useful...
 
themadhacker







PostPosted: Mon Oct 30, 2006 1:22 pm Reply with quote

runswithscissors wrote:
so did anyone ever actually get this to work?
What the hell happend here the thread just died?


I thought I was quite clear in saying that this indeed worked.

Only a small typo on someones part that I posted the correction for.

If you cant get it to work...you should probably re-read everything here.

Works like a charm!
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©