Hey,

I am needing a few things. I am using PEAR. If you guys don't know what it is then please look, http://pear.php.net/package/Mail

Anyway, my boss at work asked me to find out how to do a few things in it and well, I am stumped. Not that hard but would just like a few examples.

Here is what I am TRYING to do. :-D

1) send an email with CC and / or BCC parameters
2) send an email with one or more attacments
3) send an email via sendmail vs. smtp
4) send an email with a different "priority"

Any thoughts? Thanks,

Chad

    That class seems kind of limited. Is there a way you could use something else? PHP Mailer is a great alternative. Take a look at their examples and tutorial.

      Well, I've never used pear to send email, but here's my stab at it anyway.

      1. To send to addresses via cc or bcc, you simply have to add these headers to your message. With pear you just add it in your send line. I'll modify the example from pear's website slightly to illustrate.
      <?php
      include('Mail.php');
      
      $recipients = 'joe@example.com';
      
      $headers['From']    = 'richard@example.com';
      $headers['To']      = 'joe@example.com';
      $headers['BCC']     = 'boss@example.com';  //  Send a copy to the boss secretly.
      $headers['Subject'] = 'Test message';
      
      $body = 'Test message';
      
      $params['sendmail_path'] = '/usr/lib/sendmail';
      
      // Create the mail object using the Mail::factory method
      $mail_object =& Mail::factory('sendmail', $params);
      
      $mail_object->send($recipients, $headers, $body);
      ?>
      
      1. To send an attachment you should use the Mail_Mime pear class. And example can be found here.

      2. The factory method will let you select smtp or sendmail. The example above uses sendmail. Here's one using smtp.

      $params['host'] = '192.168.100.201';  // Internal smtp server
      $params['auth'] = true;  //  Use smtp auth
      $params['username'] = 'phpuser';
      $params['password'] = 'secret';
      
      // Create the mail object using the Mail::factory method
      $mail_object =& Mail::factory('smtp', $params);
      
      1. Setting the priority is just a matter of setting more headers. In theory the only header you have to set is "X-Priority", where 1 is highest, 3 is normal, and 5 is lowest. I understand microsoft outlook sets two additional headers, "X-MSMail-Priority" and "Importance", both with a value of "High". Can't hurt to set these two extra headers, so you might as well. I assume the first example is adequate to demonstrate setting headers.

        Thanks so much,

        I really do appreciate it. I will give them a try.

        Chad

          Write a Reply...