rbrown Posted January 16, 2008 Share Posted January 16, 2008 First off, my brain is toast at this point... Here's what I'm attempting to do: I'm writing a script that monitors software licences, scripts and servers. So I have functions that: * Monitors the licensed script for any errors in class or api functions. * Monitors the licenses and decrpyts the license for verification, renews and encrypts the license and reports any errors. * Monitors the server to make sure it can connect to the licensing server. * Monitors the local mail server that the script can mail locally. * Monitors that it can connect to two remote mail servers one for the licensor and one for me to be able to make sure things are working correctly. * auth send mail function So I have all the functions written and working and the error messages written for certain scenarios... So as you can tell, there can be quite a few different error messages. So for the auth send mail function, instead of having a huge lines of input, I put the sending information in three arrays. One for the enduser of the script, one for the client and one for me. So instead of having to do: Authorized_Send_Email( $client_from_email_address, $client_from_name, $client_to_email_address, $client_to_name, $client_bcc_email_address, $client_bcc_name, $tg_smtp_subject, $tg_smtp_message, $tg_smtp_new_line, $client_smtp_server, $client_smtp_server_port, $client_smtp_server_timeout, $client_smtp_server_username, $client_smtp_server_password, $client_smtp_server_localhost ); All I want to do is: Authorized_Send_Email( $the_array, $the_error_subject, $the_error_message ); So inside the Authorized_Send_Email function I'm calling the array elements as $the_array[from_email_address] So inside the Authorized_Send_Email so I don't have to have three functions, I need to look at the $the_array And have it use: $enduser_array[from_email_address] $enduser_array[from_name] $enduser_array[to_email_address] etc... or $client_array[from_email_address] $client_array[from_name] $client_array[to_email_address] etc... or $tome_array[from_email_address] $tome_array[from_name] $tome_array[to_email_address] etc... Based on the input to the function, I need to get the array name so I can use it inside the function. So if it is the "enduser" array it will replace all the calls inside the function with $enduser_array[from_email_address] etc... Like an if $the_array contains $enduser_array then set all the array names to $enduser_array. So that way I only need one function instead of three. Follow? I have tried it a bunch of different ways and I can't get it for some reason. And I can't find where to get the array name from a function call. Thanks, Bob Link to comment https://forums.phpfreaks.com/topic/86305-solved-array-function-question/ Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 Can we see the definition for the Authorized_Send_Email() function? Link to comment https://forums.phpfreaks.com/topic/86305-solved-array-function-question/#findComment-440923 Share on other sites More sharing options...
rbrown Posted January 16, 2008 Author Share Posted January 16, 2008 Not sure if this still works been messing with it and I accidentally overwrote the last working version... <?php Authorized_Send_Email($client_from_email_address, $client_from_name, $client_to_email_address, $client_to_name, $tg_smtp_subject, $tg_smtp_message, $client_smtp_server, $client_smtp_server_port, $client_smtp_server_timeout, $client_smtp_server_username, $client_smtp_server_password, $client_smtp_server_localhost, $client_bcc_email_address, $client_bcc_name); function Authorized_Send_Email($client_from_email_address, $client_from_name, $client_to_email_address, $client_to_name, $tg_smtp_subject, $tg_smtp_message, $client_smtp_server, $client_smtp_server_port, $client_smtp_server_timeout, $client_smtp_server_username, $client_smtp_server_password, $client_smtp_server_localhost, $client_bcc_email_address, $client_bcc_name){ $tg_smtp_new_line="\r\n"; $tg_smtp_connect = fsockopen($your_smtp_server, $your_smtp_server_port, $errno, $errstr, $your_smtp_server_timeout); $tg_smtp_response= fgets($tg_smtp_connect, 515); if(empty($tg_smtp_connect)){$tg_smtp_output="Failed to connect: $tg_smtp_response";return $tg_smtp_output;}else{$tg_smtp_log_array['connection']="Connected: $tg_smtp_response";} //Request Auth Login fputs($tg_smtp_connect, "AUTH LOGIN" . $tg_smtp_new_line); $tg_smtp_response=fgets($tg_smtp_connect, 515); $tg_smtp_log_array['authrequest']="$tg_smtp_response"; //Send username fputs($tg_smtp_connect,base64_encode($your_smtp_server_username) . $tg_smtp_new_line);$tg_smtp_response=fgets($tg_smtp_connect, 515);$tg_smtp_log_array['authusername']="$tg_smtp_response"; //Send password fputs($tg_smtp_connect,base64_encode($your_smtp_server_password) . $tg_smtp_new_line);$tg_smtp_response=fgets($tg_smtp_connect, 515);$tg_smtp_log_array['authpassword']="$tg_smtp_response"; //Say Hello to SMTP fputs($tg_smtp_connect,"HELO $your_smtp_server_localhost" . $tg_smtp_new_line);$tg_smtp_response=fgets($tg_smtp_connect, 515);$tg_smtp_log_array['heloresponse']="$tg_smtp_response"; //Email From fputs($tg_smtp_connect,"MAIL FROM: $your_from_email_address" . $tg_smtp_new_line);$tg_smtp_response=fgets($tg_smtp_connect, 515);$tg_smtp_log_array['mailfromresponse']="$tg_smtp_response"; //Email To fputs($tg_smtp_connect,"RCPT TO: $your_to_email_address" . $tg_smtp_new_line);$tg_smtp_response=fgets($tg_smtp_connect, 515);$tg_smtp_log_array['mailtoresponse']="$tg_smtp_response"; //The Email fputs($tg_smtp_connect,"DATA" . $tg_smtp_new_line);$tg_smtp_response=fgets($tg_smtp_connect, 515);$tg_smtp_log_array['data1response']="$tg_smtp_response"; //Construct Headers $headers="MIME-Version: 1.0" . $tg_smtp_new_line; $headers .="Content-type: text/html; charset=iso-8859-1" . $tg_smtp_new_line; $headers .="To: $your_to_name <$your_to_email_address>" . $tg_smtp_new_line; $headers .="From: $your_from_name <$your_from_email_address>" . $tg_smtp_new_line; fputs($tg_smtp_connect,"To: $your_to_email_address\nFrom: $your_from_email_address\nSubject: $tg_smtp_subject\n$headers\n\n$tg_smtp_message\n.\n");$tg_smtp_response=fgets($tg_smtp_connect,515);$tg_smtp_log_array['data2response']="$tg_smtp_response"; // Say Bye to SMTP fputs($tg_smtp_connect,"QUIT" . $tg_smtp_new_line);$tg_smtp_response=fgets($tg_smtp_connect, 515);$tg_smtp_log_array['quitresponse']="$tg_smtp_response"; } /* End Authorized_Send_Email */ ?> Link to comment https://forums.phpfreaks.com/topic/86305-solved-array-function-question/#findComment-440949 Share on other sites More sharing options...
rbrown Posted January 16, 2008 Author Share Posted January 16, 2008 Just noticed... the script has the $your_ and the function call has $client_ So you have to replace them to get it to work. Then show me how to switch between three arrays for the shortened version. Like this: if($the_array=='client'){ $array_set='client_array'; } fputs($tg_smtp_connect,base64_encode($array_set[username]) . $tg_smtp_new_line);$tg_smtp_response=fgets($tg_smtp_connect, 515);$tg_smtp_log_array['authusername']="$tg_smtp_response"; Or something like that... Thanks, Link to comment https://forums.phpfreaks.com/topic/86305-solved-array-function-question/#findComment-440990 Share on other sites More sharing options...
tapos Posted January 16, 2008 Share Posted January 16, 2008 Please use code tag to post your code. -- Thanks, Tapos Pal http://tapos.wordpress.com Link to comment https://forums.phpfreaks.com/topic/86305-solved-array-function-question/#findComment-440996 Share on other sites More sharing options...
rbrown Posted January 16, 2008 Author Share Posted January 16, 2008 Will do... I'm just used to using another forum where [ code ] is for html and [ php ] is for php Habits are hard to break... Link to comment https://forums.phpfreaks.com/topic/86305-solved-array-function-question/#findComment-441014 Share on other sites More sharing options...
rbrown Posted January 16, 2008 Author Share Posted January 16, 2008 Nevermind... Duh! I think I figured it out... I'm making harder than it needs to be... All I have to do is: change the arrays so the key naming conventions match each other. Then change the name of the array once inside of the function. function Authorized_Send_Email($input_array){ $array_set=$input_array; fputs($tg_smtp_connect,base64_encode($array_set[username]) . $tg_smtp_new_line);$tg_smtp_response=fgets($tg_smtp_connect, 515);$tg_smtp_log_array['authusername']="$tg_smtp_response"; Link to comment https://forums.phpfreaks.com/topic/86305-solved-array-function-question/#findComment-441086 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.