Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Pear Mail Returns Fatal Error: Failed opening required 'Mail.php'

Tags:

php

email

pear

How to include mail.php for using PHP Pear Mail. I'm using the following code in test.php file:

    require_once "Mail.php";

    $from = "<[email protected]>";
    $to = "<[email protected]>";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";

    $host = "ssl://smtp.gmail.com";
    $port = "465";
    $username = "<[email protected]>";
    $password = "testtest";

    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
        'port' => $port,
        'auth' => true,
        'username' => $username,
        'password' => $password));

    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
    } else {
      echo("<p>Message successfully sent!</p>");
    }

and the following error is encountered via this code:

  Warning: require_once(Mail.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\6525150\html\test.php on line 3

  Fatal error: require_once() [function.require]: Failed opening required 'Mail.php' (include_path='.;C:\php5\pear') in D:\Hosting\6525150\html\test.php on line 3

Can someone tell me what is the problem?

like image 589
Deepa Avatar asked Jun 20 '11 09:06

Deepa


2 Answers

Your error message is self-explanatory. Make sure you have PEAR::Mail installed on your machine, if not then please install it.

Linux:

pear install Mail

Windows:

http://www.geeksengine.com/article/install-pear-on-windows.html

If the process is done.

Then please include your Mail.php in your script (probably before you instantiate Mail object. This should probably kick your warnings away.

include "/path/to/pear/Mail.php";

or

set_include_path("/path/to/pear"); include "Mail.php";

Also make sure there is enough permission given for Mail.php for PHP to read.

like image 192
Rakesh Sankar Avatar answered Nov 15 '22 13:11

Rakesh Sankar


Check if pear is installed in the system . If yes then specify path to Pear installation directory in php.ini include_path directive

You need to install PEAR and PEAR MAIL packages to get it working

like image 25
Varun Mittal Avatar answered Nov 15 '22 13:11

Varun Mittal