PHP code with Jumi component in Joomla 3.3.1

1.2k Views Asked by At

Please can anyone help me sort out where and why this script fails to run?

    <?php

/* Variables with the values to be sent. */

if(isset($_POST['sendsms'])) {
$sms_msg="";
$owneremail="[email protected]";
$subacct="myaccount";
$subacctpwd="mypassword"; 
$sendto="".$_POST['recipients'].""; /* destination number */
$sender="".$_POST['sender'].""; /* sender id */
$msg="".$_POST['message'].""; /* message to be sent */

/* create the required URL */

$url = "http://www.smslive247.com/http/index.aspx?" /* real address for sms api */
. "cmd=sendquickmsg"
. "&owneremail=" . UrlEncode($owneremail)
. "&subacct=" . UrlEncode($subacct)
. "&subacctpwd=" . UrlEncode($subacctpwd)
. "&message=" . UrlEncode($msg)
. "&sender=" . UrlEncode($sender)
. "&sendto=" . UrlEncode($sendto)
. "&msgtype=" . UrlEncode(0);

/* call the URL */

if ($f = @fopen($url, "r"))
{
$answer = fgets($f, 255);
if (substr($answer, 0, 1) == "+")
{
 $sms_msg= "SMS to $sendto was successful.";
}
else
{
$sms_msg= "an error has occurred: [$answer].";
}
}
else
{
$sms_msg= "Error: URL could not be opened.";
}

}
?>

<style type="text/css">
body {
    font-family:Arial, Tahoma, sans-serif;
}
#contact-wrapper {
    width:430px;
    border:1px solid #e2e2e2;
    background:#f1f1f1;
    padding:20px;
}
#contact-wrapper div {
    clear:both;
    margin:1em 0;
}
#contact-wrapper label {
    display:block;
    float:none;
    font-size:16px;
    width:auto;
}
form#contactform input {
    border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
    border-style:solid;
    border-width:1px;
    padding:5px;
    font-size:16px;
    color:#333;
}
form#contactform textarea {
    font-family:Arial, Tahoma, Helvetica, sans-serif;
    font-size:100%;
    padding:0.6em 0.5em 0.7em;
    border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
    border-style:solid;
    border-width:1px;
}
#contact-wrapper .error {
    color: #F00;
}
</style>

<div id="contact-wrapper">
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="smsform">
        <div>
            <label for="name"><strong>SMS Sender:</strong></label>
          <input type="text" size="35" name="sender" id="sender" value="" class="required" />
        </div>

        <div>
            <label for="recipients"><strong>SMS Recipients:</strong></label>
          <textarea rows="15" cols="35" name="recipients" id="recipients" class="required"></textarea>
        </div>

        <div>
            <label for="message"><strong>SMS Message:</strong></label>
          <textarea rows="15" cols="35" name="message" id="message" class="required"></textarea>
        </div>
        <input type="submit" value="Send SMS" name="sendsms" />
        <input type="reset" value="Reset/Cancel" name="reset" />
    </form>
</div>

I'm trying to use it with Jumi component in a Joomla 3.3.1 website. When I run the code, it just redirects to the home page of the website. I've gone over the code but cannot detect where the code goes wrong. I appreciate any assistance with this. Thanks all.

1

There are 1 best solutions below

1
On

I think it should work if you replace

$_SERVER['PHP_SELF']

with

JURI::current(); 

All Joomla pages are rendered via index.php, which is why the former returns the homepage. JURI::current() is the way to get the current page URL within the Joomla framework.