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
nivz
New Member
New Member


Joined: May 18, 2006
Posts: 5

PostPosted: Fri May 19, 2006 6:19 pm Reply with quote

Hi guys,

I tried using the search for hours to find a complete solution for this but i couldn't, nd that's y i'm making this post.

I have the latest ravennuke installed and running fine, the only thing is it can't send activation emails to any address other than the once on my domain itself.

I contacted the hosting company and they said they've disabled php Mail() on their servers so i have to use smtp, and gave me a link to some code. I have no idea how to use that code, no idea which files to modify. So if u guys can tell me which files i have to modify it would be of great help.

here's the code they showed me.


Common Code
Code:
<?php

//new function

$to = "post@example.com";
$nameto = "Who To";
$from = "post@example.com";
$namefrom = "Who From";
$subject = "Hello World Again!";
$message = "World, Hello!";
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
?>



Function Code
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,

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{
   //SMTP + SERVER DETAILS
   /* * * * CONFIGURATION START * * * */
   $smtpServer = "mail.server.com";
   $port = "25";
   $timeout = "30";
   $username = "smtpusername";
   $password = "smtppassword";
   $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";
   }

   //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";   
}
?>
 
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17077

PostPosted: Fri May 19, 2006 10:51 pm Reply with quote

nivz, I have "cleaned up" your post for easier reference Smile

Create a file called authSendEmail.php and place the Function Code block in the file and store it in the includes folder. Now, where ever you have the php mail() function, add include_once('includes/authSendEmail.php'); to any script that uses the mail() function. Then use the Common Code to set up (replace your mail() code. So, in essence, the function authSendEmail replaces every occurrence of mail() and the Common Code is the setup code to call it. You could change the Common Code block to read
Code:
<?php

//new function

$to = "post@example.com";
$nameto = "Who To";
$from = "post@example.com";
$namefrom = "Who From";
$subject = "Hello World Again!";
$message = "World, Hello!";
include_once('includes/authSendEmail.php');
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
?>
 
View user's profile Send private message
nivz
PostPosted: Sat May 20, 2006 12:24 am Reply with quote

I think i got it, I'll give it a shot and see what happens.. Thanks so much for the info!! Very Happy

-edit-
Where can i find the code to send the activation emails? that's all i want to modify. I'm a complete noob@php so I ruined my site a couple of times and had to re install everything. (so i'm kinda scared to edit anything Sad )

-edit-

Found the mail function in Your_Account module.

Code:


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


if i change every call to

Code:


include_once('includes/authSendEmail.php');
authSendEmail($from, "MY NAME" , $user_email, $user_email, $subject, $message);


will this work?

Again, sorry for troubling you...
 
nivz
PostPosted: Sat May 20, 2006 2:36 am Reply with quote

Hi guys, I tried this and it's not working.. can someone tell me whether i'm doing anything wrong? or is there any other way to get around this? please consider that my php understaning is quite low so please be kind enough to explain in a lil detail..

Thanks....

Nivz
 
Raven
PostPosted: Sat May 20, 2006 5:58 am Reply with quote

If you used this code
Code:
<?php

//new function

$to = "post@example.com";
$nameto = "Who To";
$from = "post@example.com";
$namefrom = "Who From";
$subject = "Hello World Again!";
$message = "World, Hello!";
include_once('includes/authSendEmail.php');
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
?>

then change this code
Code:
include_once('includes/authSendEmail.php');

authSendEmail($from, "MY NAME" , $user_email, $user_email, $subject, $message);

to this
Code:
authSendEmail($from, "MY NAME" , $user_email, $user_email, $subject, $message);


Now, as to your problem in getting it to work ....

I haven't tested your Host's code. but let's assume, for the moment, that it does work. In comparing the 2 calls

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

Let's assume that under the PHP Mail() function you had this:

$user_email = "raven@ravenphpscripts.com";
$subject = "Test Email";
$message = "This is a test mail using the PHP Mail() function.";
$from = "you@yourdomain.com"; //Needs a valid email address
mail($user_email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion()); should work.

Now, mapping that to your Host's new function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message); it should look like this:
//new function

$to = "raven@ravenphpscripts.com";
$nameto = "Raven";
$from = "you@yourdomain.com"; //Needs a valid email address
$namefrom = "NIVZ";
$subject = "Test Email";
$message = "This is a test mail using the Host authSendEmail function.";

authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);

Technically speaking, that should work. Make sure you comment out the mail() function in your code.

You can test this outside of Your_Account module by doing this. Make sure that you have correctly filled in the
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "mail.server.com";
$port = "25";
$timeout = "30";
$username = "smtpusername";
$password = "smtppassword";
$localhost = "localhost";
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */

Code:
<?

//new function

$to = "raven@ravenphpscripts.com";
$nameto = "Raven";
$from = "you@yourdomain.com";  //Needs a valid email address
$namefrom = "NIVZ";
$subject = "Test Email";
$message = "This is a test mail using the Host authSendEmail function.";

$logArray = array();
$logArray = authSendEmail("From: $from\nX-Mailer: PHP/" . phpversion(), $namefrom, $to, $nameto, $subject, $message);
var_dump($logArray);

/* * * * * * * * * * * * * * 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)
{
   //SMTP + SERVER DETAILS
   /* * * * CONFIGURATION START * * * */
   $smtpServer = "mail.server.com";
   $port = "25";
   $timeout = "30";
   $username = "smtpusername";
   $password = "smtppassword";
   $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";
   }

   //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";   
return $logArray;
}
?>
 
nivz
PostPosted: Sat May 20, 2006 1:44 pm Reply with quote

I did fill the smtp bits correctly, (same settings on the forum works fine). only thing I think I've done wrong is putting

include_once('includes/authSendEmail.php');

b4 every call to authSendEmail(). If i only have to use this line once in the code, where should i put it? in the beginning of the script? or just use it before the fist call to authSendEmail() and just use the function from there after?

I replaced the mail function in the code with authSendMail().

Thanks for all the help,
Nivz.
 
Raven
PostPosted: Sat May 20, 2006 4:08 pm Reply with quote

You only need it once and I'd add it towards the top.
 
nivz
PostPosted: Sat May 20, 2006 10:50 pm Reply with quote

Hi Raven, Still no luck.. I tried to send a test message using the authSendEmail() on a test script and it first said the include file is not there. Then i moved it to the same folder as the script was and then didn't get any error messages.

but the email has not been sent.. i think it's the code my host gave me, doesnt seem to be working...

I'll contact my hosting provider again anyway and see how it goes.. Thanks a billion times for the help raven..

Regards,
Nivz.
 
spyrule
Worker
Worker


Joined: Jun 06, 2006
Posts: 105

PostPosted: Sun Jun 11, 2006 4:41 pm Reply with quote

Hello,

ok, so I've tried this test, what I did was the include the entire thing into one file, and I actually get a responce from my provider, however it still fails, here is what I get :

array(10) { ["connection"]=> string(53) "Connected: 220 smtp101.rog.mail.re2.yahoo.com ESMTP " ["authrequest"]=> string(18) "334 VXNlcm5hbWU6 " ["authusername"]=> string(18) "334 UGFzc3dvcmQ6 " ["authpassword"]=> string(27) "235 ok, go ahead (#2.0.0) " ["heloresponse"]=> string(36) "250 smtp101.rog.mail.re2.yahoo.com " ["mailfromresponse"]=> string(8) "250 ok " ["mailtoresponse"]=> string(28) "502 unimplemented (#5.5.1) " ["data1response"]=> string(8) "250 ok " ["data2response"]=> string(14) "354 go ahead " ["quitresponse"]=> string(49) "451 See Only registered users can see links on this board! Get registered or login! " }

so when going to the Only registered users can see links on this board! Get registered or login! address, it's telling me that "Bare LFs in SMTP" is the problem. I've looked at the script, and I can't see where this problem is coming from.

btw, the above output is exactly as it is shown. The outputs don't show any CR. How can I add that to the code to make it easier to read?

Thanks in advance,

Spyrule.

p.s. - btw, This is the closest I have come so far as to figure out wtf has been causing me to not be able to send via my provider. So A HUGE pre-thank you !!!!
 
View user's profile Send private message Visit poster's website
spyrule
PostPosted: Sun Jun 11, 2006 4:47 pm Reply with quote

btw,

I myself and not much of a php coder, but I do understand the principles of code, and general syntax. Also, everything else works nearly perfectly on my server, This is my last hurdle.

so..... JUMP!...


spyrule.
 
montego
Site Admin


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

PostPosted: Sun Jun 11, 2006 9:30 pm Reply with quote

Maybe try in the mail headers to end each header "node" string with "\r\n".

Sorry, having trouble reading the output above.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
spyrule
PostPosted: Sun Jun 11, 2006 10:45 pm Reply with quote

what the hell does that mean ?!?! Smile LOL!..

uhh, ok. I _think_ I know what you mean.

let me try ...
 
spyrule
PostPosted: Sun Jun 11, 2006 11:18 pm Reply with quote

HAHAHAHAHAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... I figured it out..

and it works beautifully.... now I just have to implement it into nuke.


Wooohoooo... (4 days of trying to figure out my email problems)...
 
spyrule
PostPosted: Sun Jun 11, 2006 11:35 pm Reply with quote

ok,

so here is the final update for those people, whose email servers require CR before LS (which is smtp standard I think). Minor fix to Raven's code.

BEFORE:
Code:


// (near the bottom, right after the 3 headers lines)
fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");


AFTER:
Code:


// (near the bottom, right after the 3 headers lines)
fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");


Basically, I think raven forgot the CR ( \ r ) before each new line ( \ n ).
I bolded them to indicate as such. Plus SMTP protocol requires the message to end in CRLF.CRLF . so thats why the \ r \ n . \ r \ n at the end of the last fputs command.

Anyway, it's 1:30am and I gotta work @ 6... so g'night. be back tommorow with a final update if it works throughout nuke.

Spyrule Smile

P.s. - I will sleep with a smile on my face. Cheers guys.
 
spyrule
PostPosted: Sun Jun 11, 2006 11:36 pm Reply with quote

oh yeah, the bold doesn't work inside the code window, so I removed them.
 
montego
PostPosted: Mon Jun 12, 2006 5:17 am Reply with quote

Dance-Y

glad we could help!

RavensScripts
 
spyrule
PostPosted: Mon Jun 12, 2006 7:53 pm Reply with quote

Well, ok

so I got the initial test script to work... but now I cannot figure out how to IMPLEMENT it into the registration process. I'm pretty sure its in the /Your_Account/index.php

I've added an include_once("includes/AuthSendEmail.php");
just under the initial comments section in the index file,

Then when I would see
Code:
mail($user_email, $subject, $message, "From: $adminmail\nX-Mailer: PHP/" . phpversion());
I would replace with :
Code:
authSendEmail($from , 'TUGEVE PASSWORD', $user_email, 'member info', $subject, $message);


I've hard written the "from name", and "to name", into the command, but that shouldn't make a difference?!? does it?

ANY... seriously.. ANY help would be HUGELY apreciated.
(had my hopes up all night, and don't feel like this NOT working again!).

Thanks in advance,

Spyrule.
 
montego
PostPosted: Tue Jun 13, 2006 6:25 am Reply with quote

Try changing your $from variable to what you see in the BEFORE code and see if that works, because other than that, it sure looks like it would work.

Also, I am sure you tested it. If it does not work, please be specific with how it did not work, any output produced, error messages, etc. so that we can help debug better.

Regards.
 
spyrule
PostPosted: Tue Jun 13, 2006 4:14 pm Reply with quote

yeah,

see that's the unusual part... I don't get ANY errors, nor bad output. just the generic "message has been delivered" message when doing activations.

And as for log files, I don't know where to set/look for errors from php.
 
montego
PostPosted: Tue Jun 13, 2006 9:44 pm Reply with quote

Within your config.php file there is a $display_errors = 0 (by default) -- in some installations it could say "FALSE". Set this to a 1. If you have access to some sort of host provided control panel (almost all do), you should also have access to some tool there to look at your Apache error log, which might catch different kinds of errors.

You may have the use "echo" to check the values of your variables being passed into the send function just to make sure they are getting valued / passed as you would expect them to (based on your prior testing of this function outside of nuke).
 
spyrule
PostPosted: Tue Jun 13, 2006 10:05 pm Reply with quote

Thanks,

Unfortunetly, That is part of my ghost log problem... I run my own Windows 2003 server with IIS 6, php 5.0.4, and mySQL 4.1 . I always had problem with apache in windows, so I found IIS to be fairly simple once I started using it.

I will try the config.php file though....
 
spyrule
PostPosted: Tue Jun 13, 2006 10:10 pm Reply with quote

ok,

so after enabling error generation, I found that I had called the include file twice.

removed the second one, and that error went away.

Now I essentially get NO error, but I still don't get the email.... argh!.

This is driving me bonker. Anybody know of a way to modify ravens above script so that it dumps the responce to either the screen or a file? a file would be nice and clean, and would help me figure stuff out, without having to mess with visual output.

I am sadly not a very knowledgable php coder... I can read it, understand it, but I have NO IDEA where to start to make the additions to the code to do that. ANY help is greatly apreciated.

btw, I'm sorry for being a "leach" for info... I usually try and do my research and do my own work, but this one seriously has me stumped.... Sad

Thanks,

Spyrule.
 
montego
PostPosted: Tue Jun 13, 2006 10:14 pm Reply with quote

Just do something like this within your PHP code:

echo $from.'<br>';

Change the $from variable name to whatever you need to. The '<br>' is just to force a line break in your output.
 
spyrule
PostPosted: Tue Jun 13, 2006 10:53 pm Reply with quote

Ok,

so I added the echo commands as you suggested :

example before :
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
I added:
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
echo "Login: ".$logArray['authrequest'].".<br>";

So, now I get the output :

Quote:

Connection: Connected: 220 smtp100.rog.mail.re2.yahoo.com ESMTP .
Login: 334 VXNlcm5hbWU6 .
UID: 334 UGFzc3dvcmQ6 .
Password: 235 ok, go ahead (#2.0.0) .
HELO: 250 smtp100.rog.mail.re2.yahoo.com .
Mail From: 250 ok .
RCPT To: 250 ok .
data: 354 go ahead .
data2responce: 451 See Only registered users can see links on this board! Get registered or login! .
QUIT: .


Now, the link at the bottom points to a document that talks about bare LFs.

however, I cannot find any bare lfs in the data2 nor any other section for that matter. You can view my script here :
Only registered users can see links on this board! Get registered or login!

It's fairly well easy to read...

data2 is near the bottom.

again, any suggestion or help.. or maybe its just one of those "another set of eyes" type situations.

spyrule.
 
spyrule
PostPosted: Tue Jun 13, 2006 10:54 pm Reply with quote

btw,

of course my testmail sample, has any UID/PSWs removed.
 
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 ©