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

    I have in issue with eform. When sending a message i get the dreaded

    Main mail: Mailer was unable to send mailCould not instantiate mail function.


    I’m running modx 9.6.3 on a windows IIS server 7 server with PHP5.

    I tried this script:
    <?php
    $message = "Test 1\nTest 2\nTest 3";
    mail('[email protected]', 'Testing mail function', $message);
    ?>


    But it fails with an internal 500 error.

    The error in the logs is:

    HTTP/1.1 500 Internal Server Error Server: Microsoft-IIS/7.0 X-Powered-By: ASP.NET Date: Wed, 20 Jan 2010 12:39:25 GMT Connection: close Content-Length: 223 PHP Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in \\10.0.3.22\home\gollygaloshes.com\public_html\mail.php on line 3


    Any suggestions
      • 37550 ☆ A M B ☆
      • 711 Posts
      Hi,

      The correct way to send email with just a php file is like this:


      <?php
      $to = "[email protected]";
      $subject = "Test mail";
      $message = "Hello! This is a simple email message.";
      $from = "[email protected]";
      $headers = "From: $from";
      mail($to,$subject,$message,$headers);
      echo "Mail Sent.";
      ?>

      Could you try this and let me know if you still get the 500 error which is warning about no from address being set.

      Thanks
        http://www.onesmarthost.co.uk
        UK MODX Hosting with love.
        • 4429
        • 429 Posts
        Hi,

        That message came through just fine.

        Does that mean you know what the problem is?
          • 37550 ☆ A M B ☆
          • 711 Posts
          Yep,

          If I remember right you should be setting a from field i.e. on the contact form on Onesmarthost is:


          [!eForm? &formid=`ContactForm` &from=`[+email+]` &subject=`[+subject+]` &to=`[email protected]` &ccsender=`1` &tpl=`ContactForm` &report=`ContactFormReport` &vericode=`1` &invalidClass=`invalidValue` &thankyou=`ContactFormThanks` &requiredClass=`requiredValue` &cssStyle=`ContactStyles`!]

          [+email+] is picked up from the form which the user submitted and set’s their email as the from address for the email, some hosting providers will prevent you from sending email this way so you may have to manually set the from field address like:


          [!eForm? &formid=`ContactForm` &from=`[email protected]` &subject=`[+subject+]` &to=`[email protected]` &ccsender=`1` &tpl=`ContactForm` &report=`ContactFormReport` &vericode=`1` &invalidClass=`invalidValue` &thankyou=`ContactFormThanks` &requiredClass=`requiredValue` &cssStyle=`ContactStyles`!]

          Hope that helps

          Aaron
            http://www.onesmarthost.co.uk
            UK MODX Hosting with love.
            • 4429
            • 429 Posts
            Hmm, tried both methods but get the same error.

            Main mail: Mailer was unable to send mailCould not instantiate mail function.


            Here is my call:
            [!eForm? &formid=`ContactForm` &subject=`[+subject+]` &to=`[email protected]` &ccsender=`1` &tpl=`ContactForm` &report=`ContactFormReport` &invalidClass=`invalidValue` &requiredClass=`requiredValue` &cssStyle=`ContactStyles` &gotoid=`10` &from=`[email protected]` !] 


            Here is a link to the actual form

            http://bit.ly/4QexIj
              • 37550 ☆ A M B ☆
              • 711 Posts
              I forgot to mention one more thing, is the email From Address valid for that server / domain?

              Some hosts will restrict email going out if the from address is not the same as the domainname.

              Aaron
                http://www.onesmarthost.co.uk
                UK MODX Hosting with love.
                • 4429
                • 429 Posts
                oops. Amended that, and even created a new email account - but still the extact same error message.

                I did contact my hosts, but they will not get invovled with coding issues as they call it.

                It works fine on all linux servers on the same host, just not IIS7
                  • 37550 ☆ A M B ☆
                  • 711 Posts
                  Thats not very good of them, are you able to create a php file like my example above and send mail that way on the IIS7 server, if this works then the server works fine and we have to look closer at MODx and eForm.

                  However if the php example does not work on your IIS7 server then you would need to find out from your web host what the correct method is to send email via PHP.

                  Some hosting providers require that you authenticate with the server first before sending email.

                  Aaron
                    http://www.onesmarthost.co.uk
                    UK MODX Hosting with love.
                    • 4429
                    • 429 Posts
                    <?php
                    $to = "[email protected]";
                    $subject = "Test mail";
                    $message = "Hello! This is a simple email message.";
                    $from = "[email protected]";
                    $headers = "From: $from";
                    mail($to,$subject,$message,$headers);
                    echo "Mail Sent.";
                    ?> 


                    This PHP example works perfectly regardless of what email address is in the $from = column.
                      • 4429
                      • 429 Posts
                      I have this form that works fine which i hope to use since eform doesn’t work.

                      the only issue is the it doesn’t forward the user to my thanks page.

                      How should it be modified to do that?


                      <?php
                      
                      if ($_SERVER['REQUEST_METHOD'] != 'POST') exit; // Quit if it is not a form post
                      
                      // quick way clean up incoming fields
                      foreach($_POST as $key => $value) $_POST[$key] = urldecode(trim($value));
                      
                      // get form data into shorter variables
                      // each $_POST variable is named based on the form field's id value
                      $name   = $_POST['name'];
                      $telephone = $_POST['telephone'];
                      $sender_email = $_POST['sender_email'];
                      $message = $_POST['message'];
                      $code    = $_POST['code'];
                      
                      $errors  = array(); // array of errors
                      
                      // basic validation
                      if ($name == '') {
                        $errors[] = "\n\n - Please enter your name. ";
                      }
                      
                      
                      if ($telephone == '') {
                        $errors[] = "\n\n - Please enter your telephone. ";
                      }
                      
                      if ($sender_email == '') {
                        $errors[] = "\n\n - Please enter your email address. ";
                      }
                      
                      if (sizeof($errors) == 0) {
                        // only check the code if there are no other errors
                        require_once 'securimage/securimage.php';
                        $img = new Securimage;
                        if ($img->check($code) == false) {
                          $errors[] = "\n\n Incorrect security code entered";
                        } // if the code checked is correct, it is destroyed to prevent re-use
                      }
                      
                      if (sizeof($errors) > 0) {
                        // if errors, send the error message
                        $str = implode("\n", $errors);
                        die("There was an error with your submission.  Please correct the following:" . $str);
                      }
                      
                      require_once('class.phpmailer.php');
                      
                      $time = date('r');
                      $body = "Name: ".$name."<br />";
                      $body .= "Telephone: ".$telephone."<br />";
                      $body .= "Email: ".$sender_email."<br />";
                      $body .= "Message: ".$message."<br />";
                      
                      
                      // send email
                      
                      $mail             = new PHPMailer();
                      $mail->CharSet = "UTF-8";
                      $mail->IsSMTP(); // telling the class to use SMTP
                      $mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
                      $mail->SMTPAuth   = true;                  // enable SMTP authentication
                      $mail->Host       = "mail.mydomain.com"; // sets the SMTP server
                      $mail->Port       = 25;                    // set the SMTP port for the GMAIL server
                      $mail->Username   = "[email protected]"; // SMTP account username
                      $mail->Password   = "mypassword";        // SMTP account password
                      
                      // ** CHANGE BELOW  ** 
                      
                      $mail->SetFrom('[email protected]', '[email protected]'); // Who the email is being sent FROM
                      $mail->AddReplyTo("[email protected]","My Name"); // REPLY TO
                      $mail->Subject = "Request from website";
                      
                      // ******************* 
                      
                      $mail->MsgHTML($body);
                      
                      $address = "[email protected]"; // ** Who the email is being sent TO
                      $mail->AddAddress($address, "Me"); // ** Who the email is being sent TO
                      
                      if(!$mail->Send()) {
                        echo "Mailer Error: " . $mail->ErrorInfo;
                      } else
                      
                      
                      die('Thank you'); // send success indicator
                      ?>