11 Replies Latest reply on Aug 21, 2014 11:32 AM by steelycal09

    Help with SMTP class function with authentication

    steelycal09 Level 1

      My server is no longer supporting the php mail() functionality.  I need to use SMTP class function with authentication in my php code and they suggested this to replace it: http://www.yrhostsupport.com/index.php?/Knowledgebase/Article/View/101/2/smtp-class-functi on-with-authentication-in-php-code

       

      So I tried it, but can't get it to work. This is my test form:

       

       

      <form method="post" action="forms/sendmail-test2.php" onsubmit="return checkEmail(this);">

      <script type="text/javascript" language="JavaScript">

       

      </script>

      <fieldset><legend>Info</legend>

      <label> Name </label>

        <input type="text"

        name="name" size="30" maxlength="40"/><br />

       

      <label> <span class="redText">*</span> Email </label>

          <input name="email" type="text" size="30" maxlength="40"/>

          <br />

         

      <label><span class="redText">*</span> Message </label>

        <textarea cols="40" rows="5" name="message" type="text" /></textarea><br />

          </fieldset>

         

      <input type="reset" value="Reset" />

       

       

      <input type=submit value="Submit Form" />

       

      </fieldset>

      </form>

       

      This is sendmail-test2.php where the form goes. It won't send unless I comment out the first 10 lines.

       

      <?php

      include('Mail.php');

       

      //$to = "sales@xxxxxx.com";

      //$name = $_REQUEST['name'] ;

      //$email = $_REQUEST['email'] ;

      //$message = $_REQUEST['name'] ;

       

      //$headers = "From: $email";

      //$subject = " price quote";

      //$fields = array();

      //$fields{"name"} = "Name"; 

      //$fields{"email"} = "Email";

      //$fields{"message"} = "Message";

       

       

       

      $recipients = 'sales@xxxxxx.com'; //CHANGE

       

      $headers['From']    = 'sales@xxxxxx.com'; //CHANGE

      $headers['To']      = 'sales@xxxxxx.com'; //CHANGE

      $headers['Subject'] = 'Test message';

       

      $body = 'Test message';

       

      // Define SMTP Parameters

       

      $params['host'] = 'levy.dnsbox25.com';

      $params['port'] = '25';

      $params['auth'] = 'PLAIN';

      $params['username'] = 'sales@xxxxxx.com'; //CHANGE

      $params['password'] = 'xxxxxx'; //CHANGE

       

      /* The following option enables SMTP debugging and will print the SMTP

      conversation to the page, it will only help with authentication issues. */

       

      $params['debug'] = 'true';

       

      // Create the mail object using the Mail::factory method

       

      $mail_object =& Mail::factory('smtp', $params);

       

      // Print the parameters you are using to the page

       

      foreach ($params as $p){

            echo "$p<br />";

      }

       

      // Send the message

       

      $mail_object->send($recipients, $headers, $body);

       

      ?>

       

      It used to work fine when I used

      $send = mail($to, $subject, $body, $headers);

      $send2 = mail($from, $subject2, $autoreply, $headers2);

       

      But they said I can't use it any more. I'm good with HTML and CSS but I don't know much about php. Thanks for any help integrating a from into this new code!