Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • This solution is great and works perfectly.

    To newies (like me):

    1. Create an empty file named pagelink.php (or similar) into plugins/contact-form-7/modules/
    2. Copy-paste the php code writen by schulzjan above.
    3. Save the file.
    4. Go to your Contact Form 7 admin page and add the tag [pagelink mypagelink] somewhere inside your form.
    5. Finally, add the tag [mypagelink] somewhere inside the body of the message.

    Thanks schulzjan!!

    The solution for version 2:

    Open includes/classes.php

    Add this before the function compose_and_send_mail (line 315)

    //Added to get the current URL
    function selfURL() {
    	$s = empty($_SERVER["HTTPS"]) ? ''
    		: ($_SERVER["HTTPS"] == "on") ? "s"
    		: "";
    	$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
    	$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
    		: (":".$_SERVER["SERVER_PORT"]);
    	return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
    }
    function strleft($s1, $s2) {
    	return substr($s1, 0, strpos($s1, $s2));
    }

    Then add this after $mail_body inside function compose_and_send_mail (line 324)

    //Added to send the current URL
    	$pageURL = selfURL();
    	$mail_body .= "\n\nSent from URL: $pageURL";

    Again, this is just a way to do it, but it’s better using new modules options in Contact Form 7 v2. Because then you won’t lose the code during updating.

    I have the same issue. But this plugin tries to keep as simple as posible. Maybe you can use another plugin o modify the current one (take in consideration that any update on the plugin will destroy the modification). I did this and work for me:

    Go to wp-content/plugins/contact-form-7/includes/mail.php

    Edit after line 27 (the one that starts with$mail_body =

    Add this code (or similar):

    //Added to get the current URL
    function selfURL() {
    	$s = empty($_SERVER["HTTPS"]) ? ''
    		: ($_SERVER["HTTPS"] == "on") ? "s"
    		: "";
    	$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
    	$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
    		: (":".$_SERVER["SERVER_PORT"]);
    	return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
    }
    function strleft($s1, $s2) {
    	return substr($s1, 0, strpos($s1, $s2));
    }
    $pageURL = selfURL();
    
    //Added to send the current URL
    	$mail_body .= "\n\nSent from URL: $pageURL";

    This code will add the URL after the main content of the form. Hope it works for you. And don’t forget that any update in the plugin will make this to desappear.

Viewing 3 replies - 1 through 3 (of 3 total)