I am trying to send email with cake php email component:
var $components = array('Email');
$email = new CakeEmail();
$email->from(array('me#example.com' => 'My Site'));
$email->to('xxx#gmail.com');
$email->subject('About');
$email->send('My message');
And I always get message: Couldnt send email. Internal error occured.
In error log there is "SocketException".
I am using cakephp 2.0.
How should I configure things to get it work? I don't want to use any smtp servers and so on, I just want to send simple email.
I am using WAMP on my PC.
Uncomment the line: extension=php_openssl.dll in php.ini. This will resolve your Socket problem.
One more thing I want to say is :
You are mixing two thing core library & component both. FYI
EmailComponent is now deprecated. so use core library instead.
for more details check this link http://book.cakephp.org/2.0/en/core-utility-libraries/email.html
Debug the exception.
I bet that you can't open a connection to your mail server. Looks more like it's an error with your mail server setup or the connection to it than with CakePHp.
For an easy mail server setup for windows I recommend you to use XAMPP, it comes with the preconfigured mail server Pegasus, works just easy and fast for me.
This really does look like it's an error with your mail server setup or the connection to it. However, you are confusing the CakeEmail class for the EmailComponent.
Firstly you're not trying to send a email with the emailComponent, you are using the new CakeMail class (new from 2.x).
Thus, this:
var $components = array('Email');
and this:
$email = new CakeEmail();
are two different things. The first loads the EmailComponent, but you're not using it at all. The EmailComponent as of 2.x is deprecated. In your example you're using the CakeEmail Class.
Firstly you should insure that the class is actually loaded:
App::uses('CakeEmail', 'Network/Email');
Then check if you have the configuration file in:
App/Config/email.php
I suppose you're currently using the default configuration option. This means that the default transport is 'Mail' - the PHP mail function. I suppose you're getting a SocketException, because it can't connect to a underlying mail transport agent and because it is trying to do so over a System Socket... (Which I do not think exists in Windows, but I could be wrong. I know for sure that there is something like that in the windows API for inter-process cominucation)
Anyway, using the default email configuration is ok. Read the CakePHP Book's Section on the CakeEmail class.
Related
Hello guys i just started to building web using Symfony6 - im trying to send email using mailer however it somehow require database to be configured (+ some special table created for messages...).Maybe there is some workaround so it would work without DB.. - thing is in Symfony 5 there was no problem with that.
If you comment the default configuration in config/packages/messenger.yaml
#Symfony\Component\Mailer\Messenger\SendEmailMessage: async
or set it to null your email should be sent immediately.
By default it's configured to work in async mode via messenger, that's why #glukose 's answer works. It sets sync mode and emails are sent immediately that way.
Your messenger is configured to work via Doctrine, that's why it requires DB. Like this:
MESSENGER_TRANSPORT_DSN=doctrine://default
You can use many other options, like Redis or AMQP, async mode is used for a reason after all.
Anyway async mode won't work without workers started with command php bin/console messenger:consume async. That was my problem because I wasn't aware about what was used. No errors, but emails are not actually sent with Symfony mailer!
I have implemented mod_auth_mellon in my apache httpd 2.4 webserver. I configured Mellon to authenticate when I try to access my oracle JET application.
So far all is good, when I go to http://example.com, I am redirected to my sso login page and after entering my credentials I am sent back to https://example.com.
My problem is that once I return to my application at https://example.com, I need to be able to access the Mellon-nameid attribute so I can retrieve user privilleges from a database talbe based on email address.
According to all the docs I have read, mod_auth_mellon stores the mellonUser attribute in the apache environment, and/or the response headers.
Also according to what I have read, there is no way in my JET application to access the apache environment variables, and so far I haven't found a way to examine the response headers to get the mellonUser from there either.
Is there an alternate way to access the MellonUser attribute? Can it be stored in teh Mellon cookie, or maybe put on the url as a query parameter?
Also any methods for accessing the headers would be appreciated as well.
Just posting here, even though it's an old thread.
So when you use Apache Mellon, you can supply the nameID in a header value. If you are using apache as a proxy, (I.E you successfully authenticated, now go through the proxy), the web server can access the nameID as an attribute. You can also pass whatever other SAML attributes you want (Assuming you already know how to do this, i'll leave this part out).
Now the problem is, that header value is something the web app (Backend) sees BEHIND the proxy. Javascript is ran client side, in the user's actual browser. So in this scenario it would not be able to see this value unless you tell the backend to send it forward.
As an example, if you setup Apache SAML and then have it proxy to a PHP app, and you have a page that simply dumps the headers:
<?php
foreach (getallheaders() as $name => $value) {
echo "$name: $value\n";
}
?>
OR:
<?php
var_dump($_SERVER);
?>
VIOLA, you can see the nameid and whatever other attributes! However, go to your web console, and poke around, or check out your headers... these will be different because you are getting headers from pre-proxy, while the webapp gets headers from the post-proxy.
So what can you do? In my php example, since PHP will parse first, you can grab the variable from the backend, and echo it into a script that will be ran after this is all done.
<script>
username = "<?php echo $YourHeaderNameID; ?>";
</script>
However, there is some danger to this as well. Client side Javascript and be easily modified. So if your username "johnsmith", and you wanted to change the website username to "joeschmoe", that would be trivial. You should probably have the backend provide whatever user information you require, and then use javascript to style, rearrange, do whatever with.
I'm writing a PHP library for accessing the Odoo XML-RPC API and I need to know the Odoo version of the server I'm talking to - but I can't figure out how to determine the version. Is there a certain model that will tell me or how do I do that?
UPDATE
I thought I have figured it out. The ir.module.module model will give you a list of all the installed modules. Then in the base module you look at the installed_version property. BUT this requires admin access! I need to do this as the regular user that is normally using the API.
But for anyone who has that kind of access this is what you would do. Using ripcord (see example here) you would use this line to retrive just the base module:
$models->execute_kw($db, $username, $password, 'ir.module.module', 'search_read', array(array(array('name', '=', 'base'))) );
You can get the Odoo version even without authentication from the API common endpoint. See documentation on https://www.odoo.com/documentation/12.0/webservices/odoo.html heading ”Logging in” and the first code sample there. You can find the server_version property there.
$common = ripcord::client($url.'/xmlrpc/2/common');
$common->version();
Following code is valid and working fine tested on multiple servers.
$url = 'https://###.###.###.##:8069';
$db = 'demo';
$username = 'user_name';
$password = 'password';
$common = ripcord::client("$url/xmlrpc/2/common");
$models = ripcord::client("$url/xmlrpc/2/object");
$common->version();
$uid = $common->authenticate($db, $username, $password, array());
These examples use the Ripcord library, which provides a simple
XML-RPC API. Ripcord requires that XML-RPC support be enabled in your
PHP installation.
Since calls are performed over HTTPS, it also requires that the
OpenSSL extension be enabled.
I have an AngularJS 1.5 application which is working with a Laravel 5.2 API and I'm trying to send emails at different points in the application. So I'm able to send data to Laravel and it gets recorded in the tables I specify but when it gets to sending a confirmation email it gives me this error with an HTTP status code of 500: MethodNotAllowedHttpException
Odd thing is, it works perfectly fine in local development on my laptop. But the same functions on the AWS EC2 instance and it fails when it gets to sending any email. I'm using SendGrid to manage sending emails but I don't think I need to change any settings for that.
For Example:
$emailUser = array();
$emailUser['email'] = $request->email;
$emailUser['first_name'] = $request->first_name;
$emailUser['last_name'] = $request->last_name;
$emailUser['randomStr'] = str_random(36);
$emailUser['remove_dtm'] = Carbon::now()->addWeeks(2);
//Add a password reset set to 2 weeks out for the user to register
DB::table('password_resets')->insert([
'email' => $emailUser['email'],
'token' => $emailUser['randomStr'],
'remove_dtm' => $emailUser['remove_dtm']
]);
Mail::send('email.registered_user', $emailUser, function($message) use ($emailUser)
{ $message->to($emailUser['email'], $emailUser['first_name'] . ' ' . $emailUser['last_name']);
$message->from('WSCUSTOMERPO#waterstoneco.com', 'Waterstone Faucets');
$message->replyTo('WSCUSTOMERPO#waterstoneco.com', 'Waterstone Faucets');
$message->subject("Welcome to the Waterstone Faucets Portal!");
});
When I try to reset a user's password it will create the record in the password_reset table but not send the email on the live site. Again the same function works fine on my laptop. I checked that I'm posting on the Angular side and Laravel API is expecting a post HTTP call when running this function.
What am I missing here?
Thank you greatly for your help!
There are a few things to check here,
1: Are you sure you have your .env file set up to use the correct SMTP server settings to use SendGrid. If you forgot to set this up in your .env you will be using the internal mail function. Instead of using SendGrid, I would suggest keeping it inside of Amazon for more reliability. Switching over to Amazon SES may be a great option for you.
2: If you are using the internal mail system, there is a really good article about mail from Amazon EC2 instances here: http://shlomoswidler.com/2009/07/sending-email-from-ec2.html
Just a reminder for number 1 for others that may have come here looking for help. To set your mail service in Laravel to use an smtp service, open your config/mail.php file and set the driver to use your provider (if provided by laravel). This can be done by edit the file directly or setting the environment variable MAIL_DRIVER in your .env file.
I am working over Oracle DataBase and CakePHP 2.3.
As CakePHP doesn't support Oracle (there are no drivers for it), I am using Oracle procedures or php OCI8 functions in my models.
As a result of it, I am working with CakePHP without any effective database link in the eyes of CakePHP framework.
I am trying to use the Sanitize::clean method in order to clean a comment before saving it in the database and I am having troubles as it seems to look in the database for its task.
This is the resulting error:
Database connection "Mysql" is missing, or could not be created.
And this is how I try to sanitize it:
$comment = Sanitize::clean($this->request->data['comment']);
It works perfectly well if i just do this:
$comment = $this->request->data['comment'];
Is it possible somehow to use Sanitize::clean without any configured database at CakePHP 2.3?
Thanks
The function Sanitize::clean() expects 2 arguments, by default when you do not give a second argument CakePHP uses its default values and tries to connect to a DB with the 'default' connection. After a quick glance at the Sanitize Class in the library, it appears that it is the 'escape' option that requires a DB connection. It is called by default to make a string SQL-safe.
So in your case, as you don't need a SQL connection, this request should do the trick:
$comment = Sanitize::clean($this->request->data['comment'], array('escape' => false);
Check the CookBook for more information on the Sanitize class.