We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    My hosting company provides a service where I can send SMS messages via Email through them. So I created a simple snippet, very similar to a standard contact Email snippet (in fact I ripped off most of the guts from the contactform snippet that comes with a default MODx installation).

    The service requires a very specific "to" address and subject, so those need to be configured for whatever service you will be using. I don’t know if every service like this uses this same format, but this appears to work fine for this particular one. The "to" address takes the form of "[email protected]", and the subject must be "code#accountusername".

    It’s very crude; I would like to tack an Ajax front-end onto it, among other things.

    // specific information needed for sms email service
    $to = '[email protected]';
    $subject = 'code#username';
    
    // Instructions 
    $instructions = "Fill out your name, email, and a brief SMS-style message. All fields are required.";
    
    // Success Message 
    $success = "Your message has been sent.";
    
    // Class for containing Success Message <p>
    $successClass = "message";
    
    // Failure <p> class
    $failClass = "error";
    
    // Empy Field failure message
    $emptyFields = "One of the fields was left blank. Please put something in all fields.";
    
    // General failure message
    $generalFail = "Sorry, there was an error! Please try again later.";
    
    // Bad email failure message
    $failedEmail= (isset($_POST['sms_email']))? $_POST['sms_email']: '';
    $emailFail = "The email address you supplied (".$failedEmail.") does not appear to be valid. Please try again.";
    
    if (isset($_POST['sms_send'])) { 
        $from = $_POST['sms_name'];
        $from_email = $_POST['sms_email'];
        $message = $_POST['sms_message'];
        if ( ($from == '')||($from_email == '')||($message == '') ) {
            $SendMail .= "<p class=\"$failClass\">$emptyFields</p>";
        } elseif (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})%body%quot;, $from_email)) {
            $headers = "From: $from <$from_email>\r\n";
            
            // clean out potential tomfoolery...
            $message = $modx->stripTags($message);
            
            $body = "Name: $from\nEmail: $from_email\nMessage:\n\n" . $message;
            if (mail($to, $subject, $body, $headers)) {
                $SendMail .= "<p class=\"$successClass\">$success</p>";
                return $SendMail;
            } else {
                $SendMail .= "<p class='$failClass'>$generalFail</p>";
                $send = "false";
            }
        } else {
            $SendMail .= "<p class=\"$failClass\">$emailFail</p>";
            $send = "false";
        } 
    } else {
        $SendMail .= "<p>$instructions</p>";
    }
    
    
    
    $SendMail .= '
      <div id="sms_box">
      <form id="sms_form" method="post" name="sms_form" action="[~[*id*]~]">
      <fieldset>
        <label for="sms_name">Your Name: <input type="text" class="text" name="sms_name" /><span id="n_required">Required</span></label>
        <label for="sms_email">Your Email: <input type="text" class="text" name="sms_email" /><span id="e_required">Required</span><span id="i_email"></span></label>
        <label for="sms_message">Your Message: <input type="text" class="text" name="sms_message" /><span id="m_required">Required</span></label>
        <input type="submit" name="sms_send" class="button" value="Send Message" />
      </fieldset>
      </form>
      </div>
    ';
    
    return $SendMail;
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 6726
      • 7,075 Posts
      Woaw, Susan this is great and would be even greater taking the next step for a notification system !
      I’ll go look for such services, if there are any, in France...

      Another amazing idea grin
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l&#39;outil id
        • 19684
        • 11 Posts
        I installed the snippet under the name of SMSMessager aaand...

        I called the snippet with both [[SMSMessager]] and [!SMSMessager!] but the error was the same:

        Parse error: parse error, unexpected T_STRING in F:\www\modx\manager\includes\document.parser.class.inc.php(705) : eval()’d code on line 34

        around the line with the error or problem are regular expressions....so I just watched the error tongue

        I will try to understand, but cand u give me some help on this?....maybe I’m doing something wrong
          • 10487 MODX Staff
          • 1,535 Posts
          Hi mishhh,

          I haven’t used this snippet but I think there is a quote missing in line 34, try replacing that line with this one:
          } elseif (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})%body%quot;", $from_email)) {

          Hope that helps,
          Garry
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com