Announcement

Collapse
No announcement yet.

Ad variable to a custom php file in the site folder

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Ad variable to a custom php file in the site folder

    I use a php file called formtoemailpro.php to send the ask a question about this product email. It is included in additional files.

    It has to contain the site owner's email address.

    How can I make it so that I can use the Selledeck variable '<actinic:variable name="Email" />' in this form?

    Thank you
    Jonathan Chappell
    Website Designer
    SellerDeck Website Designer
    Actinic to SellerDeck upgrades
    Graphicz Limited - www.graphicz.co.uk

    #2
    SellerDeck won't expand variables in external files so just embedding the variable won't work.

    You can pass the address as a search string parameter when calling the PHP file.

    E.g. PHP file test.php:
    Code:
    <?php
    if ( array_key_exists("email", $_GET) )
    	{
    	$email = $_GET["email"];
    	// You should sanitize $email in case of hackers
    	$sanitezedemail = filter_var($email, FILTER_SANITIZE_EMAIL);
    	// You might also want to check that it's from the same domain as the script and is a valid email address
    	echo "Address is: $sanitezedemail";
    	}
    else
    	{
    	// deal with missing address
    	echo "No site address!";
    	}
    ?>
    And it is called from a SellerDeck layout as
    Code:
    <a href="test.php?email=<actinic:variable name="Email" />">Email me</a>
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Here's another (more reliable perhaps as it doesn't let anyone tinker with the email address).

      In the bottom of Standard Javascript Header Functions put:
      Code:
      <actinic:block if="%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%3d%3d%20%22Search%22">
      	<actinic:block php="true">
      		file_put_contents('siteemailaddress.php', '<?php $my_email = "<actinic:variable name="email"/>";?>');
      	</actinic:block>
      </actinic:block>
      This will write a file siteemailaddress.php containing e.g.:
      Code:
      <?php $my_email = "YourName@YourCompanyEmail.com";?>
      Upload this file via Design / Additional Files.

      Now in your formtoemailpro.php where you had
      Code:
      $my_email = "delete these words and put the email address only in here between the quotes";
      Replace with:
      Code:
      include_once ("siteemailaddress.php");
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        Brilliant Norman. Thank you so much.
        Jonathan Chappell
        Website Designer
        SellerDeck Website Designer
        Actinic to SellerDeck upgrades
        Graphicz Limited - www.graphicz.co.uk

        Comment


          #5
          My server prefers outgoing emails to be from the same domain so in 'FormToEmailPro.php' I tend to use an address like 'website@mydomain.com' as the 'from address' even if it does not actually exist.

          The email is coming from the same domain and in the email inbox 'From Website' shows you it is from the site.

          In the email template file I put a note to reply to the 'from' address and not to just click reply.

          After a bit of head scratching I came up with this to create the 'from' address along the same lines as Norman above:

          Code:
          <actinic:block php="true">
          file_put_contents('siteemailaddress.php', '<?php $my_email = "<actinic:variable name="email"/>";?>');
          $email = "<actinic:variable name="email"/>";
          $firstbit ="website@";
          $filename ="fromemailaddress.php";
          $domain_name = substr(strrchr($email, "@"), 1);
          $pemdata = array("<?php ", "\$from_email = \"",$firstbit, $domain_name,"\" ?>");
          file_put_contents($filename, $pemdata);
          </actinic:block>
          Then by the same token as above replace

          Code:
          $from_email = "";
          with

          Code:
          include_once ("fromemailaddress.php");
          Thank you very much again to Norman for steering me on this path.

          Jonathan Chappell
          Website Designer
          SellerDeck Website Designer
          Actinic to SellerDeck upgrades
          Graphicz Limited - www.graphicz.co.uk

          Comment


            #6
            Here's the two combined and tidied so it would be easy to add additional settings:
            Code:
            <actinic:block if="%3cactinic%3avariable%20name%3d%22PageType%22%20%2f%3e%20%3d%3d%20%22Search%22">
            	<actinic:block php="true">
            		$settings = "<?php\n";
            		$email = '<actinic:variable name="email"/>';
            
            		// the My Email Address
            		$settings .= "\$my_email = '$email';\n";
            
            		// the From Email Address
            		$settings .= "\$from_email = 'website@" . substr(strrchr($email, '@'), 1) . "';\n";
            
            		$settings .= '?>';
            		file_put_contents('sitesettings.php', $settings);
            
            	</actinic:block>
            </actinic:block>
            Which will generate file sitesetting.php containing:
            Code:
            <?php
            $my_email = 'YourName@YourCompanyEmail.com';
            $from_email = 'website@YourCompanyEmail.com';
            ?>
            And use: include_once ("sitesettings.php");
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              That's beautiful. Thank you Norman.
              Jonathan Chappell
              Website Designer
              SellerDeck Website Designer
              Actinic to SellerDeck upgrades
              Graphicz Limited - www.graphicz.co.uk

              Comment

              Working...
              X