Riquelmy Melara
Riquelmy Melara

Reputation: 941

Email URL from iframe

I have a contact form which should send an email with the link of the product the user is currently watching, the problem is that I need to use iframe because the server doesnt accept PHP files, so I have this:

 $name = clearValue($_POST["name"]);
        $lastname = clearValue($_POST["lastname"]);
        $company = clearValue($_POST["company"]);
        $phone = clearValue($_POST["phone"]);
        $country = clearValue($_POST["country"]);
        $quantity = clearValue($_POST["quantity"]);
        $mail = ($_POST["mail"]);
        $message = clearValue(nl2br($_POST["message"]));
        $type_quote = clearValue($_POST["type"]);
        $page = currentPageURL();

$headers = "Content-type: text/html\r\nFrom: $fromMailStatus \r\nReply-To: $fromMailStatus";
    $body = file_get_contents("resources/mails/mail_newWebLead.htm");
    $body = str_replace("{name}",$name,$body);
    $body = str_replace("{lastname}",$lastname,$body);
    $body = str_replace("{company}",$company,$body);
    $body = str_replace("{phone}",$phone,$body);
    $body = str_replace("{country}",$iPais["nombre"],$body);
    $body = str_replace("{language}",$iLang["nombre"],$body);
    $body = str_replace("{quantity}",$quantity,$body);
    $body = str_replace("{email}",$mail,$body);
    $body = str_replace("{message}",$message,$body);
    $body = str_replace("{link}",$page,$body);
    $body = str_replace("{ip}",$ip_source,$body);

    mail($para,"New Web Lead",$body,$headers);

function currentPageURL() {
    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
        $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return $pageURL;
}

This works but it returns the page where the iFrame is being called from and I need the original URL, how could I do this?

Upvotes: 0

Views: 76

Answers (1)

Pierre
Pierre

Reputation: 1583

$_SERVER['HTTP_REFERER'] will give you the url of the calling page.

E.G

you have url http://example.com/product/12 with iFrame pointing to http://domain.com/contact.php.

$_SERVER['HTTP_REFERER'] will give you http://example.com/product/12

Upvotes: 1

Related Questions