Send a PHP array to a Perl script

T

techusky

First off, I am not sure where exactly to post this, so I'm posting to
both php.general and here...

My general problem is that I am wondering if there is a(n effective)
way to send an array from a PHP script to a Perl script. I am
developing a simple Perl script to handle automated e-mails from my
website (which is written exclusively in PHP). I would ordinarily just
stick with PHP as far as e-mailing is concerned, but I have found it
to be much more a pain trying to connect to my Gmail account via
sockets to send e-mail; the Perl route is much simpler in my opinion.

I have a form on my website that will let me specify to which users
from my site I would like to send the e-mail. Upon submitting the
form, the PHP script parses the e-mail addresses from
$_POST['user_emails'] and puts them into an array. Then what happens
is that I do something to the effect of:

foreach($user_emails as $user) {
[some code omitted here that generates the perl script]
shell_exec("perl \"./email.user.pl\"");

}

Essentially, what this does is sends out individual e-mails to each
user (it takes roughly 5-8 seconds for it to send out one e-mail, so
you can imagine if I try to send to 100 users that it takes quite a
while). But we all know that you can send a single e-mail to many
different people at the same time... This is why I am trying to send
PHP's array to my Perl script, because I could then easily add each
element in the array to one e-mail.

Any ideas? Sorry if my problem isn't clear (or if there is some
stupidly simple solution I am not thinking of... I'm not that fluent
in Perl yet).
 
N

nolo contendere

First off, I am not sure where exactly to post this, so I'm posting to
both php.general and here...

My general problem is that I am wondering if there is a(n effective)
way to send an array from a PHP script to a Perl script. I am
developing a simple Perl script to handle automated e-mails from my
website (which is written exclusively in PHP). I would ordinarily just
stick with PHP as far as e-mailing is concerned, but I have found it
to be much more a pain trying to connect to my Gmail account via
sockets to send e-mail; the Perl route is much simpler in my opinion.

I have a form on my website that will let me specify to which users
from my site I would like to send the e-mail. Upon submitting the
form, the PHP script parses the e-mail addresses from
$_POST['user_emails'] and puts them into an array. Then what happens
is that I do something to the effect of:

foreach($user_emails as $user) {
[some code omitted here that generates the perl script]
shell_exec("perl \"./email.user.pl\"");

}

Essentially, what this does is sends out individual e-mails to each
user (it takes roughly 5-8 seconds for it to send out one e-mail, so
you can imagine if I try to send to 100 users that it takes quite a
while). But we all know that you can send a single e-mail to many
different people at the same time... This is why I am trying to send
PHP's array to my Perl script, because I could then easily add each
element in the array to one e-mail.

Any ideas? Sorry if my problem isn't clear (or if there is some
stupidly simple solution I am not thinking of... I'm not that fluent
in Perl yet).

You could build a string from your PHP's array contents, joined by
whatever delimiter (it should show up in the email addresses), and
then pass that to the Perl script. Within the Perl script, split the
string to get your individual email addresses back. There are a number
of Mail modules for Perl--I know of at least one that takes comma
separated emails (Mail::Sender, I think). Also, you could open a pipe
to Unix's mailx, which I think takes space delimited email addresses.

HTH
 
S

sopan.shewale

Hi,

I think instead of trying to send mail through form/action itself -
try following:

[1]. Collect the mail details in some file on the server in some
directory (call it mailq). Each form submit will create the mail file
under mailq. So your Browser user do not have to wait till your mails
are delivered - the speed is increased.

[2]. Write the daemon or script (use Perl or any other language) to
pick up the files from mailq, deliver the mails and clean those files
once you are done.

This will helps to remove issues because of PHP/Perl integration or
running processes/scripts together.
Also helps to increase the speed of your application.


--sopan shewale
http://sopanshewale.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top