tags:

views:

101

answers:

1

I have the following code which works when i put it in any blank php page,but when i try to put the code in another php page where i already have some codes in it, i get the error:

ERRNO: 8192
TEXT: Assigning the return value of new by reference is deprecated
LOCATION: C:\xampp\php\PEAR\Mail.php, line 154,
 include('Mail.php');
        $mail = Mail::factory("mail");

        $headers = array("From"=>"[email protected]", "Subject"=>"Your order has been placed   ");
        $body = "lol";
        $mail->send("[email protected]", $headers, $body);
+1  A: 

You probably have an old version of PEAR::Mail. Could be version 1.1.14, the last stable version before the current stable version 1.2.0.

Try

pear channel-update pear.php.net
pear upgrade Mail

to get the latest version.


edit: This is not actually part of the answer but doesn't fit in a comment either:

For debugging purposes replace the factory function in pear/Mail.php by

function &factory($driver, $params = array())
{
  $driver = strtolower($driver);
  echo '<pre>Debug: driver=', $driver, "</pre>\n";
  echo '<pre>Debug: include_path=', get_include_path(), "</pre>\n";
  echo '<pre>Debug: cwd=', getcwd(), "</pre>\n";
  echo '<pre>Debug: __FILE__=', __FILE__, "</pre>\n";

  require_once 'Mail/' . $driver . '.php';
  $class = 'Mail_' . $driver;
  if (class_exists($class)) {
    $mailer = new $class($params);
    return $mailer;
  }
  else {
    throw new Exception('Unable to find class for driver ' . $driver);
  }
}
VolkerK
where do i type the above ?
chupinette
In a command shell. How did you get the version of PEAR::Mail that you already have? Didn't you use `pear install Mail`?
VolkerK
no.. i installed xampp.
chupinette
Then open a command shell, `cd C:\xampp\php` and then the two commands...
VolkerK
i get no valid packages found
chupinette
I have PEAR version 1.9.0
chupinette
Sounds like the Mail package hasn't been installed properly. Try `pear install -a Mail`. Or use http://swiftmailer.org instead of PEAR:Mail
VolkerK
it has installed Mail 1.2.0Is it ok?
chupinette
Call to undefined method PEAR_Error::send() in C:\xampp\htdocs\final\testmail.php on line 30Now i get this
chupinette
Something went wrong with `$mail = Mail::factory("mail");`. It probably didn't find pear/mail/Mail.php. I'd throw away that "installation" of pear and start anew from http://pear.php.net/manual/en/installation.php
VolkerK
When i test the code by running:http://localhost/final/testmail.php in the browser, it works, BUt in the actual page where i need this code it does not work. Even if i out the code in a function and i try to does call that function, it does not work. It works only if i put the url directly into the browser :( I dnt know what to try anymore
chupinette
Maybe the pear directory isn't in the include\_path. `echo 'path:', get_include_path();` can tell.
VolkerK
No the pear directory is in the include path
chupinette
see edit.......
VolkerK
Debug: driver=mail Debug: include_path=.;\xampp\php\PEARDebug: cwd=C:\xampp\htdocs\finalDebug: __FILE__=C:\xampp\php\PEAR\Mail.php
chupinette
...and then an exception message or what happens?
VolkerK
Nothing happens. The above is displayed and no email is sent
chupinette
Sorry, no idea then. $mail was an instance of PEAR_Error and not a mailer class according to `Call to undefined method PEAR_Error::send()`. That's why I expected the "new" code to throw the exception instead. Now that it doesn't... I'm clueless. Going to delete the answer soon as this is getting nowhere.
VolkerK
Thanks for your help though! Could you suggest me another way to send mail using php? Some links would be great!
chupinette
Yes, http://swiftmailer.org
VolkerK