We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16732
    • 592 Posts
    This is an auto-generated support/comment thread for SendToaFriend.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Add a "Send to a friend" link and form
      • 15411
      • 5 Posts
      Great snippet, working really nice. grin

      The snippet is working fine. There are just 3 things that are not yet working correct for me.

      1. When I recieve the e-mail it appears in my unwanted e-mail box, so is there something I can do about that?

      2. The link shown in the e-mail doesn’t function. There is a typo, it says http// instead of http:// so you miss the :

      3. How do I change the text: "Contact from the site" into "Contact from (mysitename)" wich is shown in the e-mail?

      Anyone who can give suggestions, feel free to do so.

      Thx.

        As a printing consultant I am pleased with what I could do for my business with MODx. Check it out at: [url]http://www.drukwerkconsultant.nl[url] See you around!
        • 7455
        • 2,204 Posts
        Hello Kars also welcome to the community nice introduction I hope you have great time here
          follow me on twitter: @dimmy01
          • 16732
          • 592 Posts
          Quote from: Kars at Sep 21, 2006, 09:03 AM

          Great snippet, working really nice. grin

          Thanks

          Quote from: Kars at Sep 21, 2006, 09:03 AM

          1. When I recieve the e-mail it appears in my unwanted e-mail box, so is there something I can do about that?

          I think it’s depending of what you put in the email chunk (images) and your mail server configuration.
          I have tested it with a yahoo box and the mail appears in the right box


          Quote from: Kars at Sep 21, 2006, 09:03 AM


          2. The link shown in the e-mail doesn’t function. There is a typo, it says http// instead of http:// so you miss the :

          I will see this problem... strange because I’m only using the PHP $_SERVER[’HTTP_REFERER’] super global do get the url


          Quote from: Kars at Sep 21, 2006, 09:03 AM

          3. How do I change the text: "Contact from the site" into "Contact from (mysitename)" wich is shown in the e-mail?

          I put a default object which is exactly what you want .... but I have just seen that it does not work.
          So you can use your own object like that :

          [!Sendtoafriend? &tpl=`STFform`  &gab=`STFemail`  &pagenext=`4` &object=`Contact from YOURSITENAME`!]
          
            • 15411
            • 5 Posts

            I put a default object which is exactly what you want .... but I have just seen that it does not work.
            So you can use your own object like that :

            [!Sendtoafriend? &tpl=`STFform`  &gab=`STFemail`  &pagenext=`4` &object=`Contact from YOURSITENAME`!]
            


            When you change this object it only changes the subject of the e-mail but not the content. In the e-mail it self there is also the sentence : "Contact from the site"

            Do I change this in the snippet-call or in the chunck/snippet?
              As a printing consultant I am pleased with what I could do for my business with MODx. Check it out at: [url]http://www.drukwerkconsultant.nl[url] See you around!
              • 7923
              • 4,213 Posts
              Quote from: laurentc at Sep 21, 2006, 05:17 PM

              Quote from: Kars at Sep 21, 2006, 09:03 AM

              2. The link shown in the e-mail doesn’t function. There is a typo, it says http// instead of http:// so you miss the :

              I will see this problem... strange because I’m only using the PHP $_SERVER[’HTTP_REFERER’] super global do get the url

              The HTTP_REFERER is being filtered through modx and there has been some "bugs" in the procedure.. Check http://modxcms.com/bugs/task/497


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 16732
                • 592 Posts
                Quote from: Kars at Sep 22, 2006, 02:09 AM


                I put a default object which is exactly what you want .... but I have just seen that it does not work.
                So you can use your own object like that :

                [!Sendtoafriend? &tpl=`STFform`  &gab=`STFemail`  &pagenext=`4` &object=`Contact from YOURSITENAME`!]
                


                When you change this object it only changes the subject of the e-mail but not the content. In the e-mail it self there is also the sentence : "Contact from the site"

                Do I change this in the snippet-call or in the chunck/snippet?

                I read a bit faster your post... For the moment your only choise is to change this in the email chunk (STFemail)

                @doze : Thanks for the link ... yeasterday tested it on a 0.9.2.1 and HTTP_REFERER was filtered, but no more problem with the 0.9.5 beta2 grin
                  • 7455
                  • 2,204 Posts
                  ok I changed the folloing to meet my needs: [edit] does NOT work ok [/edit]

                  	// form first vue  [+idpage+]
                  	if(!isset($_POST['ok'])) {
                                  $myurl= 'http://www.mydomain.org/[*alias*]';
                  		$myForm = str_replace("[+alarme+]", "", $myForm);
                                  $myForm = str_replace("[+message+]", $defaultFormText.$myurl, $myForm);
                  
                  
                  		return $myForm;
                  


                  this only works when FURL is on

                  [edit] It does work if you have this form on each page but not if its opent from in a popup ahhh stupit me [/edit]
                    follow me on twitter: @dimmy01
                    • 7455
                    • 2,204 Posts
                    I changed the index.php so it leaves the: in the url

                    another thing is that the url is not clickable in the mail its lacking an a tag (atleast the mail i get in outlook is not clickable)

                    and the /n is not working in the defould text line i changed it into
                    an dit looks good in the mail
                      follow me on twitter: @dimmy01
                      • 16732
                      • 592 Posts
                      I wanted to release a new version with:

                      - the add of new ’emailTitle’ parameter and placeholder
                      - the add of new ’defaultEmailTitle’ variable
                      - the update of defaultFormText : modify /n to

                      - the add of ann <a> tag for a clickable referer link

                      BUt I have a problem with the insertion of the <a> tag !!

                      When I put :
                      	// form first vue  [+idpage+]
                      	if(!isset($_POST['ok'])) {
                      
                      		$myForm = str_replace("[+alarme+]", "", $myForm);
                                      $myForm = str_replace("[+message+]", $defaultFormText.' <a href="'.$_SERVER['HTTP_REFERER'].'" >'.$_SERVER['HTTP_REFERER'].'</a>', $myForm);
                      
                      
                      


                      The a tag is filtered and in the mail body I have : <a rel="nofollow">http://www.mysite.com</a>

                      I have only tested it with a 0.9.2.1 and with a yahoo box.

                      If someone can test it with the 0.9.5 it will be nice.

                      Here the new snippet code :
                       /*
                       *  Name: Sendtoafriend
                       *  Version: 0.3
                       *  Author: Laurent Carbonnel
                       *  Form check system based on a Moon idea
                       *  Updated: September 24, 2006
                       *
                       *  Description:
                       *  Add a "Send to a friend" link and form
                       *
                       * Instruction:
                       * Create a new snippet named "Sendtoafriend"
                       * Copy/Paste the code of the Sendtoafriend_0.2.txt file in it
                       * Create a new snippet named "AddpopupLink"
                       * Copy/Paste the code of the AddpopupLink_1.0.txt file in it
                       * Create a new template name "pop" and copy/paste the code of the poptpl.txt file
                       * Create a new chunk name "STFform"  and copy/paste the code of the STFform_chunk.txt file
                       * Create a new chunk name "STFemail"  and copy/paste the code of the STFemail_chunk.txt file (use a erreurForm style for test errors)
                       * Create a new chunk name "STFemailOK"  and copy/paste the code of the STFemailOK_chunk.txt file
                       * Create a new page and insert the Sendtoafriend snippet inside (uncheck the "in menu" option) //It's the form page
                       * Insert the AddpopupLink snippet in the pages you want with the id of the page who content the Sendtoafriend snippet for parameter &destpageidAPL
                       * AddpopupLink exemple use : [[AddpopupLink? &destpageidAPL=`5` &widthpopAPL=`400` &heightpopAPL=`270` &textlabelAPLlink=`Send to a friend`]]
                       *
                       * Parameters :
                       *        &tpl :  form chunk name (required)
                       *	  &gab :   email html template name (see STFemail.txt)  (required)
                       * 	  &object : email object (optional)
                      *         &emailTitle : email title to use with the [+emailTitle+] placeholder tag in STFemail chunk  (optional)
                       *    use one of this 2 parameters :
                       *        &emailok : aftersend chunk name (use this parameter
                       *        &pagenext : aftersend page id redirection
                      
                      
                      
                       * Exemples of use :
                       * [!Sendtoafriend? &tpl=`MyChunkForm` &gab=`MyChunkEmail` &emailok=`MyChunkEmailOK` &object=`My object` &pagenext=`redirection page id` !]
                       *
                       * [!Sendtoafriend? &tpl=`STFform`  &gab=`STFemail`  &pagenext=`4` &object=`a friend send you this message`!]
                       * [!Sendtoafriend? &tpl=`STFform`  &gab=`STFemail`  &emailok=`STFemailOK`  &object=`a friend send you this message`!]
                      
                      
                      ADD :
                      
                      - add $emailTitle parameter and  placeholder ok
                      - Modify $defaultFormText OK
                      - add a <a> tag to  $_SERVER['HTTP_REFERER']    not working
                      
                      */
                      
                      
                      /* CORE DEFAULT PARAMETERS */
                      $defaultFormText = 'Hello, I think this page would interest you : <br/>';
                      $defaultObject = 'An email from'.$_POST['nom'];
                      $defaultEmailTitle = 'MESSAGE from '.$_POST['nom'];
                      /* CORE DEFAULT PARAMETERS */
                      
                      
                      
                      // Form and email getting chunk
                      if ($tpl) $tpl = ($chunk = $modx->getChunk($tpl)) ? $chunk:"Chunk '$tpl' not found.";
                      if ($gab) $gab = ($chunk = $modx->getChunk($gab)) ? $chunk:"Chunk '$gab' not found.";
                      
                      if(!isset($emailok) && !isset($pagenext)){
                       return "!! NO REDIRECTION !! Snippet need one of these parameters : &emailok or &pagenext";
                      }
                      else {
                      
                      $objet = (isset($object))? $object : $defaultObject;
                      $titreEmail = (isset($emailTitle))? $emailTitle : $defaultEmailTitle; 
                      
                      if(trim($emailok) != ""){
                        $pagenext = $emailok;
                      }
                      
                      
                      // Construction du formulaire
                      $output = doForm($tpl,$gab,$objet,$pagenext,$defaultFormText,$titreEmail);
                      
                      // Output
                      return $output;
                      }
                      
                      
                      
                      
                      
                      
                      // **** functions definitions **** //
                      
                      
                      function erreurForm(){
                      
                          global $erreur;
                          $erreur['NOM'] = empty($_POST['nom']);
                          $erreur['NOMAMI'] = empty($_POST['nomami']);
                          $erreur['EMAILAMI'] = !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $_POST['emailami']) ;
                          $erreur['EMAIL'] = !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $_POST['email']) ;
                          $erreur['MESSAGE'] = empty($_POST['message']);
                      
                      	return $erreur['NOM'] || $erreur['NOMAMI'] || $erreur['EMAIL'] || $erreur['EMAILAMI'] || $erreur['MESSAGE'];
                      
                      }
                      
                      
                      // Form
                      function doForm($myForm,$GabMail,$Object,$pageredirect,$defaultFormText,$titreEmail) {
                      	global $modx, $erreur ;
                      
                      	// form first vue  [+idpage+]
                      	if(!isset($_POST['ok'])) {
                      
                      		$myForm = str_replace("[+alarme+]", "", $myForm);
                                      $myForm = str_replace("[+message+]", $defaultFormText.' <a href="'.$_SERVER['HTTP_REFERER'].'" >'.$_SERVER['HTTP_REFERER'].'</a>', $myForm);
                      
                      
                      		return $myForm;
                      
                                    // Form validation
                              }
                              else {
                      
                                  		// errors
                                  	if (erreurForm()){
                      
                                  	       $myForm = str_replace("[+alarme+]", "Modify fields in red", $myForm);
                      
                                             $myForm = str_replace("[+nom+]", $_POST['nom'],$myForm);
                                             $myForm = str_replace("[+nomami+]", $_POST['nomami'],$myForm);
                                             $myForm = str_replace("[+email+]", $_POST['email'],$myForm);
                                             $myForm = str_replace("[+emailami+]", $_POST['emailami'],$myForm);
                                             $myForm = str_replace("[+message+]", stripslashes($_POST['message']),$myForm);
                      
                                             $myForm= str_replace("[+classe_nom+]", ($erreur['NOM'] ? 'erreurForm' : 'normal'), $myForm);
                                             $myForm= str_replace("[+classe_nomami+]", ($erreur['NOMAMI'] ? 'erreurForm' : 'normal'), $myForm);
                                             $myForm= str_replace("[+classe_email+]", ($erreur['EMAIL'] ? 'erreurForm' : 'normal'), $myForm);
                                             $myForm= str_replace("[+classe_emailami+]", ($erreur['EMAILAMI'] ? 'erreurForm' : 'normal'), $myForm);
                                             $myForm= str_replace("[+classe_message+]", ($erreur['MESSAGE'] ? 'erreurForm' : 'normal'), $myForm);
                                             $myForm = str_replace("[+idpage+]", $_GET['linkid'], $myForm);
                                             return $myForm;
                                  	}
                                      else {// all ok
                                             $corpsmessage = $GabMail;
                      
                                             $corpsmessage = str_replace("[+emailTitle+]", $titreEmail,$corpsmessage);
                      		       $corpsmessage = str_replace("[+nom+]", $_POST['nom'],$corpsmessage);
                                             $corpsmessage = str_replace("[+nomami+]", $_POST['nomami'],$corpsmessage);
                                             $corpsmessage = str_replace("[+message+]", stripslashes(str_replace ( "\n", "<br>", $_POST['message'])),$corpsmessage);
                      
                                             $email_exp = $_POST['email'];
                      
                      
                                             $entetedate  = date("D, j M Y H:i:s -0600");
                                             $entetemail  = "From: $email_exp \n";
                                             $entetemail .= "Cc: ";
                                             $entetemail .= " \n";
                                             $entetemail .= "Bcc: \n";
                                             $entetemail .= "Reply-To: $email_exp \n";
                                             $entetemail .= "X-Mailer: PHP/" . phpversion() . "\n" ;
                                             $entetemail .= "Content-Type: text/html;charset=iso-8859-1"."\n" ;
                                             $entetemail .= "Date: $entetedate";
                      
                                             $destMail = $_POST['emailami'];
                                             mail($destMail,$Object,$corpsmessage,$entetemail);
                      
                      
                                             if(is_numeric($pageredirect)){
                                                 $modx->sendRedirect($modx->makeUrl($pageredirect)); // page redirection
                                             }
                                             else { // emailOK chunk
                      
                                                 $output =  $modx->getChunk($pageredirect);
                                                 return $output;
                                             }
                      
                      
                                      }
                      	  }
                      }