I’ve got a mailing list (uses DadaMail) which provides a perl script (subscribe_email.pl) so that I can pass subscribers to it thorugh a PHP script.
The trouble is I can get it working when variables are passed to it via URL query strings, but when I try to hard-code variables into it it stops working. I can’t see any reason for this, it’s got me really confused.
This works: -
[php]
'; exec(escapeshellcmd($exec_command),$output); if (!empty($output)) var_dump($output); } } else { echo 'No email address given.'; } ?>[/php]
The mail address and all the parameters are passed to the subscribe_email.pl script.
But, this doesn’t work: -
[php]<?php
// set to 1 for debugging
$debuginfo = 1;
$subscriber_email = ‘[email protected]’;
$subscriber_title = ‘Mr’;
$subscriber_forename = ‘John’;
$subscriber_surname = ‘Doe’;
$subscriber_company = ‘None’;
$subscriber_country = ‘UK’;
if (isset($subscriber_email)) {
$email = $subscriber_email;
}
if (isset($subscriber_title)) {
$title = preg_replace("/[^A-Za-z ]/", “”, $subscriber_title);
}
if (isset($subscriber_forename)) {
$forename = preg_replace("/[^A-Za-z-. ]/", “”, $subscriber_forename);
}
if (isset($subscriber_surname)) {
$surname = preg_replace("/[^A-Za-z-. ]/", “”, $subscriber_surname);
}
if (isset($subscriber_company)) {
$company = preg_replace("/[^A-Za-z0-9()-.& ]/", “”, $subscriber_company);
$company = str_replace(’&’, ‘and’, $company);
}
if (isset($subscriber_country)) {
$country = preg_replace("/[^A-Za-z-.& ]/", “”, $subscriber_country);
$country = str_replace(’&’, ‘and’, $country);
}
if (isset($email)) {
$exec_command = 'perl ./subscribe_email.pl --list mylist --email '. $email;
if (isset($title)) $exec_command .= ’ --fields title '. $title;
if (isset($forename)) $exec_command .= ’ --fields forename '. $forename;
if (isset($surname)) $exec_command .= ’ --fields surname '. $surname;
if (isset($company)) $exec_command .= ’ --fields company '. $company;
if (isset($country)) $exec_command .= ’ --fields country ‘. $country;
$exec_command .= ’ --verbose 1’;
if ($debuginfo==‘0’) {
exec(escapeshellcmd($exec_command));
} else {
echo ‘exec("’ . $exec_command . ‘")
’;
exec(escapeshellcmd($exec_command),$output);
if (!empty($output)) var_dump($output);
}
} else {
echo ‘No email address given.’;
}
?>[/php]
In the second example, only the list and email parameters are passed, all the others are lost (or ignored). The --verbose 1 is recognised, though, as this triggers some output from the script (which is identical to the output from the first example).
All that’s different between the two is the way the variables are inititally set, I can’t for the life of me figure out why the second one isn’t working .
Even stranger, I tried testing with just: -
[php]<?phpexec("perl ./subscribe_email.pl --list mylist --email [email protected] --fields title Mr --fields forename John--fields surname Doe --fields company None --fields country UK --verbose 1")?>[/php]
and this doesn’t work fully either (again just the list and email parameters are passed, with the verbose output).
Unfortunately, it’s the second method I need to use as it’s tagged on to the end of a contact form processing script which initiates the subscription if a checkbox is left ticked…and all variables will be coming from this form script.
Any help greatly appreciated!