Net_SMTP2
[ class tree: Net_SMTP2 ] [ index: Net_SMTP2 ] [ all elements ]

Source for file basic.php

Documentation is available at basic.php

  1. <?php
  2.  
  3. require 'Net/SMTP2.php';
  4.  
  5. $host 'mail.example.com';
  6. $from 'user@example.com';
  7. $rcpt = array('recipient1@example.com''recipient2@example.com');
  8. $subj "Subject: Test Message\n";
  9. $body "Body Line 1\nBody Line 2";
  10.  
  11. /* Create a new Net_SMTP2 object. */
  12. if (($smtp = new Net_SMTP2($host))) {
  13.     die("Unable to instantiate Net_SMTP2 object\n");
  14. }
  15.  
  16. /* Connect to the SMTP server. */
  17. try {
  18.     $smtp->connect();
  19. catch (PEAR_Exception $e{
  20.     die($e->getMessage("\n");
  21. }
  22. $smtp->auth('username','password');
  23. /* Send the 'MAIL FROM:' SMTP command. */
  24. try {
  25.     $smtp->mailFrom($from);
  26. catch (PEAR_Exception $e{
  27.     die("Unable to set sender to <$from>\n");
  28. }
  29.  
  30. /* Address the message to each of the recipients. */
  31. try {
  32.     foreach ($rcpt as $to{
  33.         $smtp->rcptTo($to);
  34.     }
  35. catch (PEAR_Exception $e{
  36.     die("Unable to add recipient <$to>: " . $e->getMessage("\n");
  37. }
  38.  
  39. /* Set the body of the message. */
  40. try {
  41.     $smtp->data($subj "\r\n" $body);
  42. catch (PEAR_Exception $e{
  43.     die("Unable to send data\n");
  44. }
  45.  
  46. /* Disconnect from the SMTP server. */
  47. $smtp->disconnect();

Documentation generated on Mon, 11 Mar 2019 15:57:16 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.