I just take over a project,and they use Mail_mime to send email.
I am using Zend to run the project and it says :
Fatal error: Class 'Mail_mime' not found in C:\Program Files (x86)\Zend\Apache2\htdocs\dcs\config_local.php on line 76
Here is the Line 76
#include_once ($include_path.'\Mail.php');
#include_once ($include_path.'\Mime.php');
//$crlf = "\r\n";
$mimeparams['eol'] = "\n";
$mime = new Mail_mime($mimeparams); // Line 76
Can i know how to use the same Mail_mime class in Zend ?
This means that the class Mail_mime was not found.
Most probably this class is in $include_path.'\Mime.php' and was not correctly included.
That's why silencing errors is a bad idea. This class is required for your script to work, why would one silence errors on including the file where it resides?
If you remove # then you might find out that those 2 files at the top were never included. I would go even further and replace include with require if your Mime_mail is really defined there.
This has nothing to do with Zend. If you wish to use Zend_Mail you can refactor your code.
Related
I'm trying to use the Mailgun API SDK to send emails from my test server. I downloaded the SDK itself as I am not currently using Composer.
However, when I try to instantiate a Mailgun object, I get this error:
Fatal error: Class 'Mailgun\Connection\RestClient' not found in /var/www/mysite.xyz/www/inc/libs/Mailgun/Mailgun.php on line 38
Which I fixed by adding require "Connection/RestClient.php"; to the Mailgun.php file. However, this in turn caused its own error.
Fatal error: Class 'GuzzleHttp\Client' not found in /var/www/mysite.xyz/www/inc/libs/Mailgun/Connection/RestClient.php on line 41
This is included in my includes.php, so for all pages.
#Mailgun php functions
require_once "libs/Mailgun/Mailgun.php";
use Mailgun\Mailgun;
Then, when I try to use this;
# First, instantiate the SDK with your API credentials and define your domain.
$mg = new Mailgun\Mailgun("key-myactualkey");
$domain = "myactualdomain.xyz";
print "Email to send is ".$welcomeemail; #Never gets reached
It causes those fatal errors and the program grinds to a halt.
Why is this happening and how do I fix it?
I had the same problem and fixed it by using composer which is easier then you might think. Just follow these instructions (locally, on your computer, where PHP should be installed):
https://github.com/mailgun/mailgun-php/blob/master/SharedHostInstall.md
Then upload all files generated to your server in a separate directory.
Then include the following lines to your script:
require 'your/path/to/these/files/vendor/autoload.php';
use Mailgun\Mailgun;
Create a new Mailgun object like this:
$mg = new Mailgun("your-secret-key");
I'm new to Zend and am currently trying to use Swift Mailer as my messaging system. However, I keep getting this error:
Fatal error: Class 'Adviser\Controller\Swift_Message' not found
I did some research and thought it might be an autoloader issue. So I added the following two lines:
$autoloader = new StandardAutoloader();
$autoloader->registerNamespace('Swift_','/Applications/MAMP/htdocs/zsa/Swift-4.3.0/lib/classes/Swift');
I'm still getting the error. I've also set the path accordingly to "swift_required.php"
require_once '/Applications/MAMP/htdocs/zsa/Swift-4.3.0/lib/swift_required.php';
Any thoughts on how to fix this?
It looks like Swift is not namespaced, so you should use $autoloader->registerPrefix instead if available.
Using http://getcomposer.org/ is a good option too.
Ok. I have used the apparently working code(the main top answer with 136 green ticks):
Send email using the GMail SMTP server from a PHP page
in my php mail script, replacing the gmail user and pass with my own... at first I got errors that PEAR, then PEAR5 could not be found... so I copied those 2 files(I downloaded from pear site) into the script's folder...
Still, script didn't work.
I added some echoes to see where it halts, and it halts at this line(I think):
$mail = $smtp->send($to, $headers, $body);
My apache/php error log says this:
PHP Fatal error: Call to undefined method PEAR_Error::send()`
I have googled this error and found over a dozen pages but havn't found an anwser... mostly they seem to say something about "installing pear libraries."
I have not tried installing/configuring pear on my local server.... because I do not think I can install new packages on my webhost, so I need a more portable solution:
What I mean by this is a working script, and any relative class files I can just copy all into one folder to get it working..... so I can just copy this folder to any apache/php server and it will automatically work(by refrencing the script in html form), without having to install/configure some third party package on the server.
I also tried phpmailer which gave similar problems and it seems to also require pear so I don't really see the point of experimenting with phpmailer further if I cannot get pear to even work.
PHP Fatal error: Call to undefined method PEAR_Error::send()
This means you didn't get a mail object but an error object, probably because logging in failed or so. Add the following to your code:
$mail = Mail::factory(..);
if (PEAR::isError($mail)) {
echo $mail->getMessage() . "\n" . $mail->getUserInfo() . "\n";
die();
}
$mail->send(...);
Btw, using $searchengine to look for that error message would have given you the same answer.
As #cweiske states, adding the code provided by him will give the detailed error. In my case it is Unable to find class for driver smtpPHP Fatal error: Call to undefined m
ethod PEAR_Error::send()
So basically it attempted to include "Mail/smtp.php" and checkd for the Mail_smtp class, but was unable to find it. So either Mail/smtp.php doesn't exist, or including it did not define the Mail_smtp class.
To resolve this all you need to do is to download Pear mail from here and copy the mail folder on to your domain. that's it. your code should work without any issues.
Thanks that helped lead me to this error:
Unable to find class for driver smtp
Which led me to this page:
http://goonanism.com/blog/2010/06/08/using-pear-to-send-email-via-smtp/
which told me I needed additional files. after I added the files it worked.
Issue solved. But I think the requirement of those files should be documented better for people who want portable solutions like myself :)
I am trying to install xml diff ; https://github.com/mmacia/XMLdiff and i have not managed yet to make it work.Whenever i run any test example,i get
Fatal error: Interface 'PHPUnit_Framework_Test' not found in
C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php on line 85
Has anyone managed to install and use the library.I am using xampp on windows.
I believe your problem has to do with PHPUnit's Autoloader.php not being included. This file sets the php spl_autoloadspl_register function which is responsible for loading in interfaces and classes like PHPUnit_Framework_Test.
According to this SO question, you have to include the autoloader file manually. Without knowing more about your set-up and how that particular library works, I would say do something like this in the appropriate file(s):
// define phpunit path
if ( ! defined('PHPUNIT_PATH')) {
// define an absolute path to your PHPUnit dir
// CHECK THIS, i'm not good with php on windows:
define('PHPUNIT_PATH','C:\xampp\php\PEAR\PHPUnit');
}
// Then include the autoloader like this:
include PHPUNIT_PATH.'Autoloader.php';
I hope this helps you or anyone else out.
Check execution flags for C:\xampp\php\PEAR\PHPUnit\Framework\Framework\Test.php
The file needs to be executable by the user who is launching tests (probably you).
I just installed PHPUnit 3.5 on my system, upgrading it from 3.4, and I'm having some trouble with the new version. When I try to run a test, I always get the same output. Here's what I get when I try to run on the command line the StackTest example from the PHPUnit manual, example 4.1:
> phpunit StackTest
X-Powered-By: PHP/5.2.17
Content-type: text/html
PHPUnit 3.5.13 by Sebastian Bergmann.
Class StackTest could not be found in StackTest.php.
Worse yet, when I try to run it from a web browser, I get the following output:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /path/to/tests/StackTest.php on line 2
Does anyone know how to set this up? Thanks.
I had the problem you described on Windows.
The problem was in the file pear\PHPUnit\Runner\StandardTestSuiteLoader.php on line 131 an it was caused by different drive letter case in file name in the condition
if ($class->getFileName() == realpath($suiteClassFile)) {
My simple fix is to change this line to be case insensitive
if (strtolower($class->getFileName()) == strtolower(realpath($suiteClassFile))) {
phpunit MyTestClass
In my case
MyTestClass.php should be in the project home directory
it should starts with long php open tag (<?php, not <?)
it should contain class MyTestClass extends PHPUnit_Framework_TestCase {
I know this is most likely not the best way, just point for a beginner to start with.
Try
pear upgrade pear
(if it asks you to channel upgrade do so)
and then
pear install --force --alldeps phpunit/phpunit
and try again.
The 3.5 upgrade combined with a buggy pear installer (1.9.1 has a kinda annoying bug so make sure you are really on 1.9.2) can be a pain sometimes.
I think your PHPUnit Class named StackTest, and the class you want to test is also named StackTest. This will cause a path conflict in PHPUnit.
Make these 2 names different and you will get this resolved.
In my case, this problem was caused by including PHPUnit in the source file via require_once:
require_once 'phar://phpunit.phar';
Removing that line made my test case runnable.
This error can also be caused when you forget to have your test class extend the PHPUnit TestCase class, like
class MyTestClass extends \PHPUnit\Framework\TestCase { ...
I was able to fix the problem. It was a result of how I was loading the class. I used my arguments in the argument array like so and it worked. But there were a lot of other problems with the classpath etc that I had to fix first. To see a working solution look here (http://www.siteconsortium.com/h/p1.php?id=php002).
$command = new PHPUnit_TextUI_Command();
$command->run(array('test', 'testCase', 'c:\workspace\project\testCase.php'), true);
Starting from PHPUnit 9, it is required that the filename match the class name in the test.
#4105: Deprecate multiple test case classes in single file and test case class name differing from filename
So test-plugin.php with a class name PluginTest will fail with this error. To fix it, you'd need to rename the file to PluginTest.php.
Bad error message IMO.
It sounds like PHPUnit isn't on your include path. To easily test this, try this:
$ phpunit --include-path /path/to/PHPUnit StackTest