for every new user our company adds, we give them firstname.lastname@ourdomain.com that forwards to their personal address. as is, this is quite a manual process and i'd rather that this junk is self-automated as there is a great possibility of human error.
currently, the file that holds all the email addresses looks like this...
it starts off like this: - RECIP=$1
-
SHELL=/bin/sh
-
INCLUDERC=.procmailrc.local
and then displays the forwarding data: - :0
-
* $RECIP ?? ^^rose.flower=ourdomain.com$
-
{
-
:0
-
!rosesemail@charter.net
-
}
-
-
:0
-
* $RECIP ?? ^^laura.person=gurrliegirl.com$
-
{
-
:0
-
!laurasemail@pacbell.net
-
}
-
-
:0
-
* $RECIP ?? ^^freddy.jones=gurrliegirl.com$
-
{
-
:0
-
!freddysemail@pacbell.net
-
}
-
as you can see, this is something that i could loop through in php (or any language for that matter--i have no idea what language the above is, however) from a database (mysql). however, the filename has to stay the same as i do not have access to the main config file since this is a hosted server. is there any way to initialize php and then do this looping without a php file extension?? or, can i include a php file into this code somehow? i would rather not edit the file directly b/c that would mean there would still be two spots (my mysql database and this file) with the same exact data.
also, the filename is .procmailrc i'm not sure if that would make a difference in answering this question or not.
10 2017 Atli 5,058
Expert 4TB
Hi.
How is that file executed?
Theoretically the file extension shouldn't matter.
If this is executed via a CLI, the file extension wouldn't matter. Like in Linux, you should be able to do: - $ php path/to/my/file.ext
And that would execute that file as PHP, no matter what extension.
If it is executed via a HTTP server you would simply have to instruct the server to execute that type of file as PHP, just like it does with .php files.
Hi.
How is that file executed?
Theoretically the file extension shouldn't matter.
If this is executed via a CLI, the file extension wouldn't matter. Like in Linux, you should be able to do: - $ php path/to/my/file.ext
And that would execute that file as PHP, no matter what extension.
If it is executed via a HTTP server you would simply have to instruct the server to execute that type of file as PHP, just like it does with .php files.
i have no idea of finding out exactly how it is executed and i'd really have to do some research on this email program to figure that out. i'm thinking (and hoping) it would be alot quicker to do some trial and error. i'll just assume it is CLI for now...
kind of confused what the $ php path/... does. is it pointing to a file to include and then reading it? if so, i should be able to set up an external php file that generates/formats all the data from my database and then include it in my main file.
for example, i could make a file such as path/to/my/file/db.php like this... - while ($query_data){
-
echo $query_data['email'];
-
//obviously not exact, but you get the idea
-
}
and then in my .procmailrc do this... - RECIP=$1
-
SHELL=/bin/sh
-
INCLUDERC=.procmailrc.local
-
-
$ php path/to/my/file/db.php
would that be the same thing as the manual hard coding that exists now?
Hi.
How is that file executed?
Theoretically the file extension shouldn't matter.
If this is executed via a CLI, the file extension wouldn't matter. Like in Linux, you should be able to do: - $ php path/to/my/file.ext
And that would execute that file as PHP, no matter what extension.
If it is executed via a HTTP server you would simply have to instruct the server to execute that type of file as PHP, just like it does with .php files.
oh wow i just re-read that and i obviously missed what you said. i don't have any way to edit the file that executes the file. i only have the supplemental parts to work with. and i could be wrong, but i don't think telling the server to execute it as php would make a difference b/c the server never actually executes the file. i believe this program reads whatever data is in the file and that's it. i'm just wondering if there is a way to include data from a file executed in php into a file such as this or somehow embed php script into this file.
let me put it another way. i actually came up with this one from another problem i'm dealing with right now that is very similar. i have a javascript (.js) file that needs the image names/locations generated from a mysql database. i would need to use php to do gather the info from the database. how would i feed the php generated image names/locations into the .js file? my current setup is less than desirable. there has to be some sort of include function in javascript, right? same goes with my other scenario?
of course, i'm merely speculating at this point. i'm probably nowhere near the real procedure to do this.
Atli 5,058
Expert 4TB
Generating JavaScript files with PHP is no problem.
You can create .php file that outputs JavaScript, and then include that file as a .js file in your page HTML.
Like, say: -
# JavaScript.php
-
<?php
-
// Let the browser know this is supposed to be JavaScript.
-
header("Content-Type: text/javascript");
-
?>
-
function ShowRandom() {
-
alert("<?php echo MD5(mt_rand()); ?>");
-
}
-
-
# Your main HTML file
-
<html>
-
<head>
-
<script type="text/javascript" src="JavaScript.php"></script>
-
</head>
-
<body onload="javascript: ShowRandom();">
-
</body>
-
</html>
-
Which would show the MD5 hash generated by PHP in a JavaScript alert window.
I don't really know what to do with the other file you were talking about earlier. I don't recognize the language it is using so I can't really say how to use it.
Would it not be possible to simply edit that file using PHP?
You know the syntax, and as I understand it, you are simply trying to automate the process of altering that file. Why not simply alter the file itself, rather than try to dynamically create it each time it is read?
Generating JavaScript files with PHP is no problem.
You can create .php file that outputs JavaScript, and then include that file as a .js file in your page HTML.
Like, say: -
# JavaScript.php
-
<?php
-
// Let the browser know this is supposed to be JavaScript.
-
header("Content-Type: text/javascript");
-
?>
-
function ShowRandom() {
-
alert("<?php echo MD5(mt_rand()); ?>");
-
}
-
-
# Your main HTML file
-
<html>
-
<head>
-
<script type="text/javascript" src="JavaScript.php"></script>
-
</head>
-
<body onload="javascript: ShowRandom();">
-
</body>
-
</html>
-
Which would show the MD5 hash generated by PHP in a JavaScript alert window.
I don't really know what to do with the other file you were talking about earlier. I don't recognize the language it is using so I can't really say how to use it.
Would it not be possible to simply edit that file using PHP?
You know the syntax, and as I understand it, you are simply trying to automate the process of altering that file. Why not simply alter the file itself, rather than try to dynamically create it each time it is read?
ah, i like that javascript trick. that is slick. much better than having all the messy javascript displayed directly in the page source.
yes, i have considered editing it directly in php. it looks like i may have to settle for that although it is not the most ideal solution. i was hoping that i could allow my users to edit the database in a linked table in microsoft access. so this could get messy if i can't figure out what language this file is in and generate the data from mysql. i'll just have to do some research i guess! i appreciate your replies, Atli. you helped me out a bunch!
Heya, n8kindt.
The file you are editing is a procmailrc file.
You can execute shell scripts inside of Procmail "recipes" (for example, calling a PHP script and passing off the email to that script).
Replace all those individual email checks with: -
:0:
-
| /usr/local/bin/php /path/to/processing/script.php
-
Replace '/usr/local/bin/php' with the actual path to the PHP binary (use `which php` if you don't know) and '/path/to/processing/script.php' with the PHP script that you want to use to connect to the database to process the email.
This will cause your email server to pass every single email to the PHP script, which will then be responsible for final delivery (most likely using the mail() function).
As this represents the extent of my knowledge, I will go ahead and move this thread to the Linux forum so that our resident Linux Experts will be able to help you out should you run into any trouble.
Heya, n8kindt.
The file you are editing is a procmailrc file.
You can execute shell scripts inside of Procmail "recipes" (for example, calling a PHP script and passing off the email to that script).
Replace all those individual email checks with: -
:0:
-
| /usr/local/bin/php /path/to/processing/script.php
-
Replace '/usr/local/bin/php' with the actual path to the PHP binary (use `which php` if you don't know) and '/path/to/processing/script.php' with the PHP script that you want to use to connect to the database to process the email.
This will cause your email server to pass every single email to the PHP script, which will then be responsible for final delivery (most likely using the mail() function).
As this represents the extent of my knowledge, I will go ahead and move this thread to the Linux forum so that our resident Linux Experts will be able to help you out should you run into any trouble.
oh wow, that is great information! thank you so much for all your help! i feel like i'm on the right track now.
alright, well i already foresee one thing that i will need to know. how do i extract all the email information (body, subject, etc) in order to send it to php from there? or is there a way to set it up so that php evaluates the email address and bounces back the required information to procmail?
Hm....
That one's tricky. I think Procmail hands it off to PHP and then says, "Ok, have fun. I'm done with you now."
You can test it out by creating a simple PHP script: -
file_put_contents('/some/path/test.txt', print_r($argv, true));
-
Then send an email to an address hosted on your mail server and open the test.txt file that the script created (you might want to change the '/some/path' part). You should get a pretty good idea of what PHP is getting from Procmail.
In terms of handling the email itself, and I could be wrong (it's been known to happen before), but I think you'd need to use mail() to finish sending the email.
I'll go ping the Linux Experts and see if any of them knows any more.
Hm....
That one's tricky. I think Procmail hands it off to PHP and then says, "Ok, have fun. I'm done with you now."
You can test it out by creating a simple PHP script: -
file_put_contents('/some/path/test.txt', print_r($argv, true));
-
Then send an email to an address hosted on your mail server and open the test.txt file that the script created (you might want to change the '/some/path' part). You should get a pretty good idea of what PHP is getting from Procmail.
In terms of handling the email itself, and I could be wrong (it's been known to happen before), but I think you'd need to use mail() to finish sending the email.
I'll go ping the Linux Experts and see if any of them knows any more.
thank you for all your help! i will be testing out your suggestion shortly.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Peter |
last post by:
Hi,
So many times, I have seen compile warning: "you used a char* without
initilize it", probably on the code like this:
------------
char* ptr;
func(..., ptr);
----------
|
by: qazmlp |
last post by:
// Test.C
Line-300: namespace
Line-301: {
Line-302: std::vector<std::string> vecaNS ;
Line-303: }
The 'SUN Forte 7 C++ Compiler' reports the following warning for the
above code:...
|
by: Mark Hannon |
last post by:
I am trying to initialize an array only once so it can be seen & used by
any functions that need it. As I understand it, if a variable is
declared by itself outside of any functions, its scope is...
|
by: www.brook |
last post by:
hi, I have a class
class A
{
const int m_a;
const int m_b;
}
m_a can be initialized at the constructor
A():m_a(2)
|
by: removeps-generic |
last post by:
Hi. I'm using placement new to re-initialize part of an object. Is
this OK?
struct BaseImp
{
All& r_all;
BaseImp(All& all) : r_all(all)
};
struct Calc::Imp : public BaseImp
|
by: toton |
last post by:
Hi,
In C++ when I initialize an array it, also initializes the class that
it contains, which calls the default constructor. However, I want to
initialize the array only (i.e reserve the space) and...
|
by: thinktwice |
last post by:
char a = { 0 }
is it ok?
|
by: BrandonG |
last post by:
I am working on a JNI project, the env->NewStringUTF function will only accept a const char as a parameter.
The trouble I am having is that within the native method I need to modify the string...
|
by: Bob Altman |
last post by:
Hi all,
If I have a class that includes an instance of a struct as a member, how do
I initialize that struct? I can't find a syntax for the constructor
"initializer list" that works.
For...
|
by: Timothy Madden |
last post by:
Hy
static members of non-integral type need to be declared in the class,
but defined (and constructed or initialized) outside the class.
Like this
class SystemName
{
public:
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |