Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Warning: include_once(Net/SMTP.php): failed to open stream

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.

like image 599
user3441151 Avatar asked Nov 30 '22 15:11

user3441151


1 Answers

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.

like image 198
user3441151 Avatar answered Dec 21 '22 06:12

user3441151