We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19036
    • 119 Posts
    Hello,

    I fund a free piece of code that can be a perfect light "tell a friend" snippet,
    the only thing that doesn’t work is the current page id (in between ## ## ) !

    Can somebody have a look ?


    <?php
    if (isset($_POST['submit'])){
    
    $to="".$_POST['friendemail']."";
    
    $subject="".$_POST['yourname']." wants you to check this out!";
    
    $mail_from="from: ".$_POST['youremail']." \n";
    
    $mail_from .="Content-Type: text/html; charset=utf-8 \n";
    
    $message="<font size=\"2\" face=\"Verdana\"> <b>".$_POST['friendemail']."</b>,<br />
    ".$_POST['yourname']." wants you to check this website!!:<br />
    
    ##########################<a href=\"[~id~]\">yourwebsite</a> </font>"; ##########################
    
    $sentmail = mail($to,$subject,$message,$mail_from);
    
    echo "We told your friend!";
    
    
    }else{
    
    ?>
    
    <form action="" method="post">
    Your Name:<br />
    <input type="input" name="yourname" /><br />
    Your Email:<br />
    <input type="input" name="youremail" /><br />
    Friend name:<br />
    <input type="input" name="friendname" /><br />
    Friend email:<br />
    <input type="input" name="friendemail" /><br /><br />
    
    <input type="submit" name="submit" value="Tell Your Friend" />
    </form>
    
    <?php }
    ?>


    What do I need to change ?

    Thanks a lot for your help.

    Mehdi
      Scuse my english...I&#39;m swiss
      • 20289
      • 958 Posts
      Use [(site_url)] instead of <a href=\"[~id~]\">yourwebsite</a>
        [img]http://i10.tinypic.com/52c4eir.gif[/img][/td]
        [td][Wiki] [Persian support forum]
        [SVN] [RTL SVN Branch] [bugs] [FishEye+Crucible] [Learn MODx!] | [My Google Code]
        [font=tahoma][برای دسترسی به راهنمای فارسی به [url=http://www.modxcms.ir]
        • 19036
        • 119 Posts
        Hi MotSmart !

        Thanks but I tried your solution and it didn’t work, I don’t get any hyperlink in my email...

        Is the problem the two \ ?


          Scuse my english...I&#39;m swiss
          • 19036
          • 119 Posts
          So I also tried many things like to call my snippet with [[tellafriend]] or [!tellafriend!]

          If it works it’s a new snippet easy an useful!

          Nothing work, can someone help me ?

          Thanks
          Mehdi

            Scuse my english...I&#39;m swiss
            • 20289
            • 958 Posts
            Quote from: mehdi at May 11, 2008, 12:17 PM

            I don’t get any hyperlink in my email...
            So what do you get instead?, Blank space or your site URl or ...?
              [img]http://i10.tinypic.com/52c4eir.gif[/img][/td]
              [td][Wiki] [Persian support forum]
              [SVN] [RTL SVN Branch] [bugs] [FishEye+Crucible] [Learn MODx!] | [My Google Code]
              [font=tahoma][برای دسترسی به راهنمای فارسی به [url=http://www.modxcms.ir]
              • 20289
              • 958 Posts
              Is that code lines you quoted here is all your snippet source?, if so there is raw html that basically needs to be included in chunks or printed out within php code and a <? php } ?> tag in your last lines of quoted code that is completely useless.
                [img]http://i10.tinypic.com/52c4eir.gif[/img][/td]
                [td][Wiki] [Persian support forum]
                [SVN] [RTL SVN Branch] [bugs] [FishEye+Crucible] [Learn MODx!] | [My Google Code]
                [font=tahoma][برای دسترسی به راهنمای فارسی به [url=http://www.modxcms.ir]
                • 4310
                • 2,310 Posts
                WebLogin uses this to make the url for the email
                $url = $modx->config['server_protocol'].'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$modx->makeURL($modx->documentIdentifier

                or
                $modx->makeURL($modx->documentIdentifier)

                might help.
                I agree with MotSmart your PHP doesn’t look right, but then again I’m only beginning to realise how little I know!
                  • 19036
                  • 119 Posts
                  Now with
                  $modx->makeURL($modx->documentIdentifier)
                  I get in my email:

                  test wants you to check this website!!:
                  (1837)
                  _________

                  So now how to "hyperlink" this number ?
                  I tried to make an href...no succes.

                    Scuse my english...I&#39;m swiss
                    • 3749
                    • 24,544 Posts
                    Mehdi,

                    I believe your php is correct as far as I can see. The final section is needed since you are dropping out of php to produce the form (not how I would have done it, but I don’t see any errors) and need to drop back into php to have the final curly brace -- leaving it out would produce a php syntax error.

                    Here’s a quick look at another way to do it.
                    <?php
                    
                    $output = "";
                    
                    if form submitted {
                    
                        //send the email here
                    
                        $output .= "your message has been sent";
                    
                    } else {
                    
                        $output .="<form>";
                        // $output .= your form here 
                       $output .="</form>;
                    
                    }
                    
                    return $output;



                    As far as the URL, I think this will do what you want:

                    $url = $modx->makeUrl([~id~], '', '', 'full');


                    Note that the second and third arguments are two single quotes not a double quote as they might appear.

                    I also wanted to mention a few other things.

                    First, it apppears that, as written, the page can be pretty easily hijacked since all it looks for is a submit and uses whatever _POST variables it gets. I’m not a mail hijacking expert but it looks like someone could pretty easily send zillions of messages through your page to various people they want to annoy and they would all appear to be coming from you.

                    Second, many ISPs now have the PHP mail() function turned off so the page would appear to work, but no mail would be sent. MODx has its own mail function that includes an SMTP alternative but that would involve some more complicated code and parameters in the snippet call to tell the snippet whether to use mail() or SMTP.

                    Hope this helps,

                    Bob


                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 19036
                      • 119 Posts
                      Thanks everybody for the help, but it still not working...so I think I forget it !

                      Anyway perhaps this portion of code will help someone one day...

                        Scuse my english...I&#39;m swiss