I want to send email by using Gmail. For this, I just run the following command
pear install Mail Mail_Mime
My php file (filename.php) code is given below
<?php
  require_once "Mail.php";
  $from = '[email protected]';
  $to = '[email protected]';
  $subject = 'Hi!';
  $body = "Hi,\n\nHow are you?";
  $headers = array(
      'From' => $from,
      'To' => $to,
      'Subject' => $subject
  );
  $smtp = Mail::factory('smtp', array(
          'host' => 'ssl://smtp.gmail.com',
          'port' => '465',
          'auth' => true,
          'username' => '[email protected]',
          'password' => 'password'
      ));
  $mail = $smtp->send($to, $headers, $body);
  if (PEAR::isError($mail)) {
      echo('<p>' . $mail->getMessage() . '</p>');
  } else {
      echo('<p>Message successfully sent!</p>');
  }
?>
When I run this "filename.php" by using below command
php filename.php
I got the following Error
PHP Warning:  include_once(Net/SMTP.php): failed to open stream: No such file or directory in /usr/share/pear/Mail/smtp.php on line 365
PHP Warning:  include_once(): Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /usr/share/pear/Mail/smtp.php on line 365
PHP Fatal error:  Class 'Net_SMTP' not found in /usr/share/pear/Mail/smtp.php on line 366
I am using CentOS 7.
Now it's Working for me. I just use the below Steps to resolved this :
1. pear upgrade --force --alldeps http://pear.php.net/get/PEAR-1.10.1
2. pear clear-cache
3. pear update-channels
4. pear upgrade
5. pear upgrade-all
6. pear install Auth_SASL
7. pear install pear/Net_SMTP
After that everything is working fine.
Thanks Everyone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With