We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4273
    • 356 Posts
    Using multiple subjects doesn’t seem to be working in the contactform snippet i removed the word static but still not sure how this is suppose work
    // enter "static" in order to use the static subject line
    $subject_type = "";
    $static_subject = "[mystuff] ".$modx->config[’site_url’];

    // Otherwise use an array of possible subjects
    $subject_array[] = "Survey Info";
    $subject_array[] = "Company Info";
    $subject_array[] = "Other Info";

    are each of these suppose to match up with the recipient ?
    what is this ["Your Text Here"] below is that a subject ?

    // Recipient ... add or remove lines as needed
    // Format (as few or as many as desired):
    // $recipient_array["Your Text Here"] = ’email@domain’;
    $recipient_array["mystuff"] = "$email";

    its a bit confusing how the contact form puts everything together too much code he he
      SMF Bookmark Mod - check it out
      http://mods.simplemachines.org/index.php?mod=350
    • The recipients array allows you to somewhat hide the real email addresses. For example, "Support Department" could go to [email protected]...
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 10472
        • 22 Posts
        I’ve got the same problem. I’ve set the code as follows:

        <?php
        // enter "static" in order to use the static subject line
        $subject_type = "";
        $static_subject = "[Web Inquiry] ".$modx->config['site_url'];
        
        // Otherwise use an array of possible subjects
        $subject_array[] = "General Inquiries";
        $subject_array[] = "Company Info";
        $subject_array[] = "Other Info";
        ?>


        But this just returns an empty subject line.

        Looking at the code, the ’dynamic’ subject line is populated from the form field ’subject’:

        $the_subject = ($subject_type=="static") ? "$static_subject" : $_POST['subject'];


        Yet there is no field ’subject’ in the generated form?

          • 10472
          • 22 Posts
          Having put into action, I’ve thought about this some more. It seems that the ’dynamic’ subject line may be overkill and could be adequately replaced by an improved subject line that reflects the ’regarding’ field. I’ve therefore amended the original code to append the first part of the recipient array to the subject line. e.g. ’[Website] - Sales enquiry’

          Amdended code:
          <?php
          // Email / Contact Form
          //
          // Simple XHTML validating email form, that sends different subjects and messages. 
          // people in a company.
          //
          // revised by G Flower 21 July 2006
          //
          // Version 1.0
          // September 9, 2005
          // [email protected]
          //
          
          // DO NOT ALTER THE FOLLOWING TWO LINES
          $recipient_array = array();
          
          ///////////////////////////////////
          //  <-----  BEGIN CONFIG  ----->
          ///////////////////////////////////
          // Edit only what's between the quotation marks in the lines below.
          // These will be the subjects that your users can choose from popup
          // lists. You can have as many as you want. Each one must be set up like so:
          // Make sure to remove empty ones that you aren't using. Just delete the entire line.
          
          // Generic email to use for all parts. You can edit
          // the individual instances for more control.
          // Defaults to the built-in email notification account which is set in the System Configuration.
          // Can be set by using as follows:
          // [[ContactForm? &sendTo=`[email protected]`]]
          $email = (isset($sendTo))? $sendTo : '[(emailsender)]';
          
          
          // enter the subject line
          
          $the_subject = "Web Inquiry";
          
          
          // Recipient ... add or remove lines as needed
          // Format (as few or as many as desired): 
          // $recipient_array["Your Text Here"] = '[email protected]';
          $recipient_array["Sales"] = '[email protected]';
          $recipient_array["Accounts"] = '[email protected]';
          $recipient_array["Website"] = '[email protected]';
          
          // enter "static" in order to use the solo recipient
          $recipient_type = "";
          $static_recipient = "$email";
          
          // Instructions 
          $instructions = "Please select the type of message you'd like to send so we can route it properly. All fields are required.";
          
          // Success Message
          $success = "Thanks for contacting [(site_url)]. Someone will get back to you soon. You may submit another message in the form below.";
          
          // 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['email']))? $_POST['email']: '';
          $emailFail = "The email address you supplied does not appear to be valid. Please try again.";
          
          // Debug mode for testing
          $debug = false;
          
          //  <-----  END CONFIG  ----->
          ///////////////////////////////////
          $SendMail = '';
          if ($debug && $_POST) {
          	$SendMail .= "POST variables from Document ID [*id*]:\n";
          	foreach ($_POST as $key => $value) {
          		$SendMail .= "\t$key => $value\n";
          	}
          }
          
          $from= '';
          $from_email= '';
          $message= '';
          
          $postSend= isset($_POST['send'])? $_POST['send']: 'false';
          if ($postSend == 'true') { 
              $todata = explode("|", $_POST['to']);
              $to = ($recipient_type=="static") ? $static_recipient : $todata[0];
              $from = $_POST['name'];
              $from_email = $_POST['email'];
              $the_subject .= " - " . $todata[1];
              $message = $_POST['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,4})$", $from_email)) {
                  $subject = $the_subject;
                  $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>";
                      $SendMail .= ($debug) ? "<p>$to\n$headers\n$subject\n$body</p>" : '';
                      $from="";
                      $from_email="";
                      $message="";
                  } else {
                      $SendMail .= "<p class='$failClass'>$generalFail</p>";
                      $send = "false";
                  }
              } else {
                  $SendMail .= "<p class=\"$failClass\">$emailFail</p>";
                  $send = "false";
              } 
          } else {
              $SendMail .= "<p>$instructions</p>";
          }
          $SendMail .=<<<EOD
          <div class="emailform">
              <form method="post" name="EmailForm" id="EmailForm" action="[~[*id*]~]" >
                  <fieldset>
                      <input type="hidden" name="send" value="true" />
                      <label for="name">Your Name: <input type="text" name="name" id="name" size="30" value="$from" /></label>
          
                      <label for="email">Your Email Address: <input type="text" name="email" id="email" size="30" value="$from_email" /></label>
          
                      <label for="to">Regarding: 
                      <select name="to" id="to">
          EOD;
          
                  foreach ($recipient_array as $key=>$value) {
                      $SendMail .= "<option value=\"{$value}|{$key}\">{$key}</option>\n";
                  }
          
          $SendMail .=<<<EOD
                      
                      </select>
                        </label>
                      <label for="message">Message: 
                      <textarea cols="50" rows="10" name="message" id="message">$message</textarea>
                      </label>
                      
                      <label>Send this message:<input type="submit" value="Send" class="button" /></label>
                  </fieldset>
              </form>
          </div>
          EOD;
          ?>











            • 4273
            • 356 Posts
            with this amended code I get a parse error unexpected $end
              SMF Bookmark Mod - check it out
              http://mods.simplemachines.org/index.php?mod=350
              • 10472
              • 22 Posts
              Sorry - my code includes the php tags at the beginning (<?php) and end (?>). Delete these from your snippet and try again.
                • 4273
                • 356 Posts
                ok got it so no parse error but form does not show up in page

                i’m calling it like [[ContactForm]]
                  SMF Bookmark Mod - check it out
                  http://mods.simplemachines.org/index.php?mod=350
                • Forms have to be called uncached or they won’t work. That of course doesn’t mean there aren’t other problems!
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 10472
                    • 22 Posts
                    Hi bugsmi0,

                    Sorry you haven’t had any luck with is. I’m still a novice when in comes to ModX and PHP, so I can’t offer much more advice. I’m calling it from a non-cacheable page using the snippet call [[ContactForm]] and all seems to be working. See it for yourself at the temporary URL:

                    http://domain1118191.sites.fasthosts.com/contact

                    I’ve tested it using IE6 and Firefox (both on PC) without any problems. Is there any code being generated, or is it completely blank?
                      • 4273
                      • 356 Posts
                      I have it uncached

                      parse error says syntax error unexpected $end in document.parser.class.inc.php(705)

                      all that shows is the error,

                      would it because I changed the snippet name to test ?

                      i’m calling it as ContactForm2
                        SMF Bookmark Mod - check it out
                        http://mods.simplemachines.org/index.php?mod=350