Sending email with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
utahfriend
Forum Commoner
Posts: 34
Joined: Thu Nov 10, 2005 12:25 pm
Location: Bountiful, Utah

Sending email with PHP

Post 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!
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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.
utahfriend
Forum Commoner
Posts: 34
Joined: Thu Nov 10, 2005 12:25 pm
Location: Bountiful, Utah

Post 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.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

did yu include the file that contains the class at the top of the page where you're using it?
utahfriend
Forum Commoner
Posts: 34
Joined: Thu Nov 10, 2005 12:25 pm
Location: Bountiful, Utah

Post by utahfriend »

Yup. I did an include exactly like the guy who wrote it did on his page that worked.
utahfriend
Forum Commoner
Posts: 34
Joined: Thu Nov 10, 2005 12:25 pm
Location: Bountiful, Utah

Post by utahfriend »

I tried everything suggested and it still does not work. Any more suggestions?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

google phpmailer and use that program. ?:-D
Post Reply