4

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 = 'from@gmail.com';
  $to = 'to@gmail.com';
  $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' => 'from@gmail.com',
          '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.

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
user3441151
  • 1,880
  • 6
  • 35
  • 79
  • The message is pretty clear, the file Net/SMTP.php is not found – Antony Jul 24 '17 at 11:44
  • @Antony I can see `smtp.php` insdei `/usr/share/pear/Mail/` – user3441151 Jul 24 '17 at 11:45
  • 1
    Is your PEAR directory in the include_path? – Álvaro González Jul 24 '17 at 11:45
  • 1
    You should remove the tag `phpmailer`, since you're actually using Pears Mail class, and not phpmailer (which is it's own mail library). – M. Eriksson Jul 24 '17 at 11:45
  • @ÁlvaroGonzález How can I check that, PEAR directory in the include_path? – user3441151 Jul 24 '17 at 11:47
  • @MagnusEriksson Which line should I have to remove, Please suggest to me? – user3441151 Jul 24 '17 at 11:49
  • Please refer this link this will help you https://stackoverflow.com/questions/2284468/problem-with-php-pear-mail – Anand Pandey Jul 24 '17 at 11:51
  • You had tagged this question with `phpmailer`. I removed the tag for you. – M. Eriksson Jul 24 '17 at 11:54
  • @AnandPandey `WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to update WARNING: "pear/Auth_SASL" is deprecated in favor of "pear/Auth_SASL2" Did not download optional dependencies: pear/Auth_SASL, use --alldeps to download automatically pear/Net_SMTP requires PEAR Installer (version >= 1.10.1), installed version is 1.9.4 pear/Net_SMTP can optionally use package "pear/Auth_SASL" (version >= 1.0.5) pear/Net_Socket requires PEAR Installer (version >= 1.10.1), installed version is 1.9.4 install failed` – user3441151 Jul 24 '17 at 11:56
  • @AnandPandey When I run `pear install Net_SMTP` It gives me the above Error which is mentioned in my previous comment. – user3441151 Jul 24 '17 at 11:57
  • use --alldeps to download automatically – Anand Pandey Jul 24 '17 at 12:38
  • @AnandPandey like this `pear install Net_SMTP --alldeps` ? – user3441151 Jul 24 '17 at 12:43
  • Simplest way to see `include_path` is `phpinfo()`. Alternatively, `ini_get()`. But adding paths is something you'd be doing somewhere in your code; if you need to ask, you aren't doing it. – Álvaro González Jul 24 '17 at 12:49
  • You're not looking for `/usr/share/pear/Mail/smtp.php`, but for `Net/SMTP.php`. Do you have a Net folder in pear/mail? – Antony Jul 24 '17 at 12:51
  • pear install --alldeps – Anand Pandey Jul 24 '17 at 12:51
  • this will help you https://stackoverflow.com/questions/2119195/yum-install-php-pear-on-centos – Anand Pandey Jul 24 '17 at 12:53
  • I have one question. If I have to install `pear-1.10.1` on centos. So what should be the command for installing this specific version 1.10.1 by using `yum install` – user3441151 Jul 24 '17 at 13:04

2 Answers2

16

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.

user3441151
  • 1,880
  • 6
  • 35
  • 79
3

For Windows Machines -

Net_SMTP is one implementation of the SMTP protocol. You'll need to install that extension. By running the following command in CMD.

pear install Net_SMTP

Be sure your have pear installed and setup in your environment path.

Quickee
  • 321
  • 1
  • 6
  • 13