Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Calling a PHP function from within Perl

by tobyink (Canon)
on Jul 27, 2019 at 21:00 UTC ( [id://11103516]=note: print w/replies, xml ) Need Help??


in reply to Calling a PHP function from within Perl

Probably your best bet is to write a helper script called something like sendMail-cli.php something like this:

<?php require_once 'sendMail.php'; extract(json_decode(file_get_contents('php://stdin'))); sendMail($fromName, $fromEmail, $to, $cc, $bcc, $subject, $messageHtml +, $messageText);

And then from Perl, you can pass data to that:

use JSON; my %mail = ( fromName => 'Alice', fromEmail => 'alice@example.com', to => 'bob@example.net', cc => 'carol@example.net', bcc => 'dave@example.org', subject => 'Test message', messageHtml => '<p>Test</p>', messageText => "Test\n", ); open my $sm, '|php sendMail-cli.php' or die 'could not open pipe to se +nd mail'; print {$sm} encode_json(\%mail); close $sm;

There are probably nicer ways to do it, but that's quick and easy.

Code is untested, but should give you a general idea.

(For bonus points, make sure that sendMail-cli.php cannot be called directly via your webserver, to avoid creating a spam gateway.)

Replies are listed 'Best First'.
Re^2: Calling a PHP function from within Perl
by DaisyLou (Sexton) on Jul 28, 2019 at 03:49 UTC
    Many thanks! I'll give it a try tomorrow!

      If you need help with avoiding creating a spam gateway, let me know, but that's probably a longer conversation.

        Thanks friend. I'm not quite there yet.
        PHP Notice: Undefined variable: fromName in /etc/my/lib/sendMail-cli. +php on line 4 PHP Notice: Undefined variable: fromEmail in /etc/my/lib/sendMail-cli +.php on line 4 PHP Notice: Undefined variable: to in /etc/my/lib/sendMail-cli.php on + line 4 PHP Notice: Undefined variable: cc in /etc/my/lib/sendMail-cli.php on + line 4 PHP Notice: Undefined variable: bcc in /etc/my/lib/sendMail-cli.php o +n line 4 PHP Notice: Undefined variable: subject in /etc/my/lib/sendMail-cli.p +hp on line 4 PHP Notice: Undefined variable: messageHtml in /etc/my/lib/sendMail-c +li.php on line 4 PHP Notice: Undefined variable: messageText in /etc/my/lib/sendMail-c +li.php on line 4 Invalid address: Invalid address:
        Any ideas?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11103516]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2024-04-25 19:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found