We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 407
    • 10 Posts
    Hi i have recently installed modx on my web site and when trying to use the standard contact form on the site i get the folowing error.

    ’Could not instantiate mail function’ can anyone help me with this porblem?

    Thanks
      • 30223
      • 1,010 Posts
      Read this first and provide some more information about the problem...
        • 27406
        • 12 Posts
        Hello, I’m having the same problem.

        Server

        • PHP Ver - 4.4.4
        • API - CGI
        • OS - Linux infong 2.4 #1 SMP
        Browser/Client

        • Ver - ie7
        • OS - XP
        ModX

        • Ver - 0.9.5
        • [li]Snippet Call -
        [!eForm? &formid=`QuoteForm` &subject=`request quote` &to=`[email protected]` &ccsender=`1` &tpl=`QuoteForm` &report=`QuoteFormReport` &gotoid=`1`  !]

        • eform Ver - 1.4.1

        All I’ve done is created my chunks using the instructions and included the snippet above on the page.
        If I forgot to include some info please let me know.
          • 7923
          • 4,213 Posts
          Is mail setuped correctly in your server environment?

          try doing a php page with this content (replace the mail address with your mail address):
          <?php
          $message = "Test 1\nTest 2\nTest 3";
          mail('[email protected]', 'Testing mail function', $message);
          ?> 
          


          Access that page and see what happens, if no errors appear, go to your mail and see if you got the mail. If it doesn’t work, contact your server host and ask why.


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 27406
            • 12 Posts

            The PHP page worked fine. Received email with 0 errors.

            I’ve also been going through my chunks and double-checking and can’t seem to find any errors.......
              • 7923
              • 4,213 Posts
              EForm uses phpmailer class from modx to send the mails and configures it to use mail() function to send the mail. Maybe you could try with a bit more complex mail() call to see if that works ok too:

              <?php
              $to      = '[email protected]';
              $subject = 'Testing mail function';
              $message = 'Test 1\nTest 2\nTest 3';
              $headers = 'From: [email protected]' . "\r\n" .
                  'Reply-To: [email protected]' . "\r\n" .
                  'X-Mailer: PHP/' . phpversion();
              
              mail($to, $subject, $message, $headers);
              ?> 
              


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 27406
                • 12 Posts

                That also worked fine. No errors.
                  • 7923
                  • 4,213 Posts
                  Well.. I don’t know what’s going on with it.. This is the function where you fail:

                  <?php
                      /**
                       * Sends mail using the PHP mail() function.  
                       * @access private
                       * @return bool
                       */
                      function MailSend($header, $body) {
                          $to = "";
                          for($i = 0; $i < count($this->to); $i++)
                          {
                              if($i != 0) { $to .= ", "; }
                              $to .= $this->to[$i][0];
                          }
                  
                          if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
                          {
                              $old_from = ini_get("sendmail_from");
                              ini_set("sendmail_from", $this->Sender);
                              $params = sprintf("-oi -f %s", $this->Sender);
                              $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, 
                                          $header, $params);
                          }
                          else
                              $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
                  
                          if (isset($old_from))
                              ini_set("sendmail_from", $old_from);
                  
                          if(!$rt)
                          {
                              $this->SetError($this->Lang("instantiate"));
                              return false;
                          }
                  
                          return true;
                      }
                  ?>
                  


                  So the php mail() function calls returns false. Maybe there are some "security" settings on your server that makes them fail, maybe something looks at the content of the mail and thinks it bad (it’s encoded). Or maybe your environment doesn’t like the params.. Or...

                  You could try to see which mail() function is used, eg replace them with die("1"); and die("2");. Then try to modify the mail() call to see what it doesn’t like eg. remove the params, try to set some static title/body text, etc..

                  EDIT: and the phpmailer class is in /manager/includes/controls/class.phpmailer.php


                    "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                    • 27406
                    • 12 Posts
                    Looking at my settings, it says that "safe_mode" is OFF

                    Would that adversely affect this line:
                    if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)


                    I’ll look into the other things you mentioned too, thanks for helping me out. smiley

                      • 10573
                      • 101 Posts
                      My eform doesn’t send mail either. What is even more odd is that I can’t upgrade the snippet from 1.4.2 to 1.4.3. When I click to save the snippet, it just shows a preview of my site in the right pane of the manager? This is the second site I have created where eform seems to fail to upgrade the snippet. I can FTP the inc fine.

                      Operating system : Linux
                      PHP version 4.4.6
                      MySQL version 4.1.21-standard

                      Hmmm, I tried that mail test and it didn’t work for me. Could it be the fact that my MX points to google mail?

                      I did a trace with cpanel and it gave me this error:
                      virtual_aliases via virtual_aliases router forced address failure

                      SOLVED!
                      had to change the mx record in my cpanel to point to google since google is managing my mail.