PHP SMTP Mail class issue - php

Ok here is the issue. I send an html email to my users.
I can't just send content text/html html in my headers because my host don't like it! They suggested to use SMTP.
So I had to install Pear id did. Then I had to install the Mail extension. I did.
Now I grab a code from the web to try it out and I get the error message
Fatal error: Class 'Mail' not found in /home/alain/php/Mail/mail.php on line 51
I'm calling that file with a require_once();. Now the line 51 in mail.php is
class Mail_mail extends Mail {
Its only the class statement!! The installation is brand new. The host use Cpanel

I found out that by default the Ubuntu's php-pear does not include the PEAR::Mail package. It's easily fixable, though:
pear install Mail
pear install pear/Net_SMTP
pear install pear/Auth_SASL
If that does not work, you might want to check your PEAR installation, by following this guide: http://pear.php.net/manual/en/installation.checking.php

You need to require() the file that has the Mail class, otherwise your Mail_mail class has nothing to extend.

There is a mistake in the mail.php.
firstly make sure you require('../php/Mail/mail.php) before doing any email coding.
Then open up the php/Mail/mail.php and put the following code in before the first class:
require('../php/Mail.php')
for some reason the coding in the hasnt included this and the class Mail it extends cannot be reached.

Related

PHP: include files without composer

I have to check the InAppPurchases receipts with my PHP server.
I would use this script in order to achieve my goal.
I'm running on a shared hosting server, so I'm not able to install or use composer. How can I still use and include the above mentioned PHP script?
I already included the following lines:
require '../lib/validate_inapp_purchase/iTunes/PurchaseItem.php';
require '../lib/validate_inapp_purchase/iTunes/Response.php';
require '../lib/validate_inapp_purchase/iTunes/Validator.php';
use ReceiptValidator\iTunes\Validator as iTunesValidator;
But the script throws the following error:
Fatal error: Class 'GuzzleHttp\Client' not found in /homepages/11/htdocs/app/lib/validate_inapp_purchase/iTunes/Validator.php on line 130
Use composer locally (on your machine) and then upload everything (including vendor folder) to the hosting server.

Laravel Error On Server for mailer

I have tried setting up this project in two different environments and keep getting the same error regardless of PHP version
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class mailer does not exist' in /var/www/sos/laravel/vendor/laravel/framework/src/Illuminate/Mail/vendor/illuminate/container/Container.php:779\nStack trace:\n#0 /var/www/sos/laravel/vendor/laravel/framework/src/Illuminate/Mail/vendor/illuminate/container/Container.php(779): ReflectionClass->__construct('mailer')\n#1 /var/www/sos/laravel/vendor/laravel/framework/src/Illuminate/Mail/vendor/illuminate/container/Container.php(659): Illuminate\\Container\\Container->build('mailer', Array)\n#2 /var/www/sos/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(644): Illuminate\\Container\\Container->make('mailer', Array)\n#3 /var/www/sos/laravel/vendor/laravel/framework/src/Illuminate/Mail/vendor/illuminate/container/Container.php(890): Illuminate\\Foundation\\Application->make('Illuminate\\\\Cont...')\n#4 /var/www/sos/laravel/vendor/laravel/framework/src/Illuminate/Mail/vendor/illuminate/container/Container.php(851): Illuminate\\Container\\Container->reso in /var/www/sos/laravel/vendor/laravel/framework/src/Illuminate/Mail/vendor/illuminate/container/Container.php on line 779
After about 5-6 hours of testing i cannot get this error to go away.
Make sure that there is no mail notification service is activated (Mail Service)
See:
https://laravel.com/docs/5.3/mail
Make sure that composer require guzzlehttp/guzzle dependency.
After making sure this dependency. After this dependency
Check your .env file for mail configuration
check your config/mail.php
and finally check App\Mail\Myfiles.php
files to make sure of the configuration that your web app support.
Check you app.php file for mail service provider Illuminate\Mail\MailServiceProvider::class, line if not exist then place it and update composer after clear artisan cache.
UPDATE
If above detail will not work for you, you need to check your .env file for unwanted space. Some time this error was thrown because one of the values in this file had space. Remove that space and check.

Symfony2 - Class XXX not found

I have deployed a Symfony Application to a one.com server. I wrote a Mail service that sends my emails via SwiftMailer.
Now, since one.com has no phar-extensions allowed, composer cannot be updated via ssh. So I generated the classmap locally with
composer update -o
Whenever I try to get the Mail service, the application throws an error:
Fatal error: Class
'Stocksolutions\ShopBundle\DependencyInjection\Mail' not found in
/customers/4/b/b/stocksolutions.be/httpd.www/releases/20150204201140/app/cache/dev/appDevDebugProjectContainer.php
on line 3602
I have searched the composer classmap and the class that isn't found is inside it:
'StockSolutions\\ShopBundle\\DependencyInjection\\Mail' => $baseDir . '/src/StockSolutions/ShopBundle/DependencyInjection/Mail.php'
Furthermore, I can get other services in the container, f.e. those from the FOSUserBundle, but getting my custom services throws an error. Also, I don't get these errors when testing locally..
Any ideas?
It's case-sensitive problem.
Your error:
Fatal error: Class
'Stocksolutions\ShopBundle\DependencyInjection\Mail' not found
Small letter s in Stocksolutions namespace for PSR forces to search for the file /src/Stock**s**olutions/ShopBundle/DependencyInjection/Mail.php, but exist /src/Stock**S**olutions/ShopBundle/DependencyInjection/Mail.php.
On local system likely Windows, where the path/filenames case-insensitive, error does not occur.
P.S. Most likely a typo in class namespace is in the bundle service description (services.yml/services.xml).

pear mail error

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 :)

Mail_mime in zend

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.

Categories