B4J Question [BANano] [SOLVED] Request assistance in sending HTML via inline PHP Mail function

alwaysbusy

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
You wrote a tutorial yourself back in the days
All this time me is thinking about the BANanoServer implementation... That is a b4j jar lib and I can use in BANano via the BANanoServer?

Phew, now where do I start? #ThinkingAloud

My mind has not even began to grasp how the BANanoServer stuff works. Ok, will have to deep dive learning.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Ola

I found the issue, I was using BANano.CallInlinePHPWait inside a library, this does not work as it needs to be used inside your module.

So this is what Im using.

B4X:
'send the email
    Dim es As Map = BANanoShared.BuildPHPEmail("[email protected]", "[email protected]", "", "BANanoMJML Email", MJMLApp.html)
    Dim email As String = BANano.CallInlinePHPWait("EmailSender", es)
    Log(email)

BuildPHPEmail is used to build the map variable to be passed to the PHP call

B4X:
'build the map to send an email to use in callinlinephp
Sub BuildPHPEmail(sfrom As String, sto As String, scc As String, ssubject As String, smsg As String) As Map
    Dim se As Map = CreateMap("from":sfrom, "to":sto, "cc":scc, "subject":ssubject, "msg":smsg)
    Return se
End Sub

The PHP

B4X:
#if PHP
function EmailSender($from, $to, $cc, $subject, $msg) {
    $hdr  = 'MIME-Version: 1.0' . "\r\n";
    $hdr .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $hdr .= 'X-Mailer:PHP/' . phpversion() . "\r\n";
    $hdr = "From:" . $from . "\r\n"; 
    $extra = '-f '. $from; 
    $hdr .= "Cc: " . $cc . "\r\n"; 
    $response = (mail($to, $subject, $msg, $hdr, $extra)) ? "success" : "failure"; 
    $output = json_encode(Array("response" => $response)); 
    header('content-type: application/json; charset=utf-8'); 
    echo($output); 
}
#End If

Thanks!
 
Upvote 0
Top