Page 1 of 1

Sending email with PHP

Posted: Fri Nov 11, 2005 10:16 am
by utahfriend
I had asked someone to write a program for me in PHP. He setup an email class to send emails. It works great in the one program he set up to send an invoice:

Code: Select all

C_Email::email_html($o_c->getSiteemail(),$o_c->getSiteemail(),$message,"New Order Placed At ".$o_c->getSitename(),$user_id);
C_Email::email_html("$order[customer_bill_name]" ,"$order[customer_email]",$message,"Your Receipt From ".$o_c->getSitename(),$user_id);
But when I try to send an email on my contact me page, (I don't want the customer order etc on a contact page) it doesn't work:

Code: Select all

C_Email::email_html2($contactname,$contactemail,$message,$subject,$myname',$myemail,$myreplyemail,$from);
Here is the email class he wrote:

Code: Select all

<?
  // inclue in document head
  // create a new object $o_email = new e_mail; syntax
  // ue it syntax $o_email->function($value);
  class C_Email
   {
    function my_mail($to, $subject, $message, $headers,$from)
     {
      require_once("GLOBAL/smtp.php");
      $smtp=new smtp_class;
      $smtp->direct_delivery=0;     /* Set to 1 to deliver directly to the recepient SMTP server */
      $smtp->timeout=10;            /* Set to the number of seconds wait for a successful connection to the SMTP server */
      $smtp->data_timeout=0;        /* Set to the number seconds wait for sending or retrieving data from the SMTP server.
                                        Set to 0 to use the same defined in the timeout variable */
      $smtp->debug=0;               /* Set to 1 to output the communication with the SMTP server */
      $smtp->html_debug=0;          /* Set to 1 to format the debug output as HTML */
      $smtp->pop3_auth_host="";     /* Set to the POP3 authentication host if your SMTP server requires prior POP3 authentication */
      $smtp->user="";               /* Set to the user name if the server requires authetication */
      $smtp->realm="";              /* Set to the authetication realm, usually the authentication user e-mail domain */
      $smtp->password="";           /* Set to the authetication password */
      if(!function_exists("GetMXRR"))
       {
        $_NAMESERVERS=array();
         include("GLOBAL/getmxrr.php");
       }
      $headers .= "Subject: $subject\r\n";
      $smtp->SendMessage($from, array( $to ), $headers, $message);
    /*  if($smtp->SendMessage($from, array( $to ), $headers, $message))
        {
         echo "Message sent to $to OK.\n";
        }
       else
        {
         echo "Cound not send the message to $to.\nError: ".$smtp->error."\n";
        } */
     }

     //send an email with html in it - all fields need to be complete
     function email_html($contactname,$contactemail,$message,$subject,$id,$from)
      {
        include_once( "Company.php");
        $o_company = new Company($id);
        $myname = $o_company->getSitename();
        $myemail = $o_company->getSiteemail();
        $myreplyemail= $o_company->getSiteemail();
        if($contactname == 'us')//email sent to us
          {
           $contactname = $o_company->getSitename();
          }
        if($contactemail == 'us')// email sent to us
          {
           $contactemail = $o_company->getSiteemail();
          }
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers .= "From: ".$myname." <".$myemail.">\r\n";
        $headers .= "To: ".$contactname." <".$contactemail.">\r\n";
        $headers .= "Reply-To: ".$myname." <".$myreplyemail.">\r\n";
        $headers .= "X-Priority: 1\r\n";
        $headers .= "X-MSMail-Priority: High\r\n";
        $headers .= "Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")."\r\n";
        //$headers .= "X-Mailer:Mercury/32 v3.32";

        C_Email::my_mail($contactemail, $subject, $message, $headers,$from);
      }
    //send an email with html in it - all fields need to be complete
     function email_html2($contactname,$contactemail,$message,$subject,$myname,$myemail,$myreplyemail,$from)
      {
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers .= "From: ".$myname." <".$myemail.">\r\n";
        $headers .= "To: ".$contactname." <".$contactemail.">\r\n";
        $headers .= "Reply-To: ".$myname." <".$myreplyemail.">\r\n";
        $headers .= "X-Priority: 1\r\n";
        $headers .= "X-MSMail-Priority: High\r\n";
        $headers .= "Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")."\r\n";
        //$headers .= "X-Mailer:Mercury/32 v3.32";

        C_Email::my_mail($contactemail, $subject, $message, $headers,$from);
      }


 

   }
?>
The guy that wrote the program for me is too busy to help anymore.... and I am stuck! Any idea what is wrong when I try to send an email in my contact page?

Thanks for any help!

Posted: Fri Nov 11, 2005 10:23 am
by jayshields
Dont bother with his class and just use PHP's mail() function. It's easy enough to use and would probably take less time to learn from scratch than his whole class.

Posted: Fri Nov 11, 2005 10:23 am
by Charles256

Code: Select all

C_Email::email_html2($contactname,$contactemail,$message,$subject,$myname',$myemail,$myreplyemail,$from);
what's up with that random quote after $myname ???
yeah,remove that quote and see if it works.

Posted: Fri Nov 11, 2005 10:29 am
by utahfriend
The extra quote was a typo when I copied and pasted into the forum. It isn't in my PHP code. sorry...

mail() does not work either. I even had a program using mail() function that worked on another server, but will not work on my new server.

Posted: Fri Nov 11, 2005 10:30 am
by Charles256
did yu include the file that contains the class at the top of the page where you're using it?

Posted: Fri Nov 11, 2005 10:45 am
by utahfriend
Yup. I did an include exactly like the guy who wrote it did on his page that worked.

Posted: Fri Nov 11, 2005 11:24 am
by utahfriend
I tried everything suggested and it still does not work. Any more suggestions?

Posted: Fri Nov 11, 2005 11:25 am
by Charles256
google phpmailer and use that program. ?:-D