Sendmail Subject in Laravel 5.1 - email

I want send email with subject using variable , this is code
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , $data, function($msg){
$msg->from('mygmail.com', 'Avil');
$msg->to('mygmail#gmail.com', 'Avil')->subject('Welcome to Laravel 5.1');
});
return redirect()->route('contact.index');
}
I wanna subject not "Welcome to Laravel 5.1", Subject is
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , $data, function($msg){
$msg->from('mygmail#gmail.com', 'Hung Nguyen');
$msg->to('mygmail#gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}
When I running display error :
Undefined variable: data
Please help me. Thank you so much

You have to pass along $data to the callback in your send method. Refer the line where Mail façade is used.
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , function($msg) use($data){
$msg->from('mygmail#gmail.com', 'Hung Nguyen');
$msg->to('mygmail#gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}

Related

Request timeout - integrate third party library with codeigniter 3

Im working on API integration InPost API Create shippment. I try integrate third party library inpost with codeigniter 3 from GitHub.
https://github.com/imper86/php-inpost-api
I install this library via composer.
View:
<?php echo form_open('inpost_controller/inpost_shippment_post'); ?>
<div class="form-group">
</div>
</div>
<?php echo form_close(); ?><!-- form end -->
Then I call in controller:
require FCPATH . 'vendor/autoload.php';
Full code file Controller:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
require FCPATH . 'vendor/autoload.php';
use Imper86\PhpInpostApi\Enum\ServiceType;
use Imper86\PhpInpostApi\InpostApi;
class Inpost_controller extends Admin_Core_Controller
{
public function __construct()
{
parent::__construct();
}
/**
* Create shippment Inpost Post
*/
public function inpost_shippment_post()
{
$token = 'xxxxx';
$organizationId = 'xxxxx';
$isSandbox = true;
$api = new InpostApi($token, $isSandbox);
$response = $api->organizations()->shipments()->post($organizationId, [
'receiver' => [
'name' => 'Marek Kowalczyk',
'company_name' => 'Company name',
'first_name' => 'Jan',
'last_name' => 'Kowalski',
'email' => 'test#inpost.pl',
'phone' => '888888888',
'address' => [
'street' => 'Malborska',
'building_number' => '130',
'city' => 'Kraków',
'post_code' => '30-624',
'country_code' => 'PL',
],
],
'sender' => [
'name' => 'Marek Kowalczyk',
'company_name' => 'Company name',
'first_name' => 'Jan',
'last_name' => 'Kowalski',
'email' => 'test#inpost.pl',
'phone' => '888888888',
],
'parcels' => [
['template' => 'small'],
],
'insurance' => [
'amount' => 25,
'currency' => 'PLN',
],
'cod' => [
'amount' => 12.50,
'currency' => 'PLN',
],
'custom_attributes' => [
'sending_method' => 'parcel_locker',
'target_point' => 'KRA012',
],
'service' => ServiceType::INPOST_LOCKER_STANDARD,
'reference' => 'Test',
'external_customer_id' => '8877xxx',
]);
$shipmentData = json_decode($response->getBody()->__toString(), true);
while ($shipmentData['status'] !== 'confirmed') {
sleep(1);
$response = $api->shipments()->get($shipmentData['id']);
$shipmentData = json_decode($response->getBody()->__toString(), true);
}
$labelResponse = $api->shipments()->label()->get($shipmentData['id'], [
'format' => 'Pdf',
'type' => 'A6',
]);
file_put_contents('/tmp/inpost_label.pdf', $labelResponse->getBody()->__toString());
}
}
When I post form, after 30 sec I get error 500 Internar Error Server Request timout.
And now im not sure how to debug now. I enable error log in CI3 application/logs/ I open this file but I not see any error related to this.
Could be a defect, or missing http2 setup/cfg.
Since the header in https2 protocol has shorter header on packs.
Not sure doe
https://caniuse.com/http2 < short http2 (TLS, HTTPS) overview
https://factoryhr.medium.com/http-2-the-difference-between-http-1-1-benefits-and-how-to-use-it-38094fa0e95b < http2 as protocol overview in 5 min

Argument 1 passed to GuzzleHttp\Client::send() must implement interface

hi I am new to laravel and I am trying to consume the api with laravel 8 I have a problem with my POST and I do not understand
public function storeEntreprise(Request $request){
$request->validate([
'name' => 'required',
'email' => 'required',
'phone_number'=>'required',
'address' => 'required',
'password' => 'required',
'password_confirmation' => 'required'
]);
$client = new Client();
$post = $request->all();
$url = "http://flexy-job.adsyst-solutions.com/api/entreprises-store";
$create = $client->request('POST', $url, [
'headers' => [
'Content-Type' => 'text/html; charset=UTF8',
],
'form-data' => [
'name' => $post['name'],
'email' => $post['email'],
'phone_number' => $post['phone_number'],
'address' => $post['address'],
'logo' => $post['logo'],
'password' => $post['password'],
'password_confirmation' => $post['password_confirmation']
]
]);
//dd($create->getBody());
echo $create->getStatusCode();
//echo $create->getHeader('Content-Type');
echo $create->getBody();
$response = $client->send($create);
return redirect()->back();
}
Can you help me please
You calling (accidentally?) $response = $client->send($create); where $create is response of API request you made ($create = $client->request('POST', $url, ...).
So PHP reports you that you can't pass ResponseInterface where RequestInterface required.
Also, you echo's body of response, and return redirect response at same time. So browser will not show you API response (because of instance back redirect).

Attempted to call method "getClientId" on class "ArrayObject"

I'm using Payum 0.12 + Paypal Express Checkout and got this error on complete action:
Attempted to call method "getClientId" on class "ArrayObject" in
DetailsController.php on line...
Here is controller code:
<?php
namespace Custom\CustomBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Payum\Core\Registry\RegistryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Model\OrderInterface;
use Payum\Core\Request\GetHumanStatus;
use Payum\Core\Request\Sync;
class DetailsController extends Controller
{
public function completeAction(Request $request) {
$token = $this->get('payum.security.http_request_verifier')->verify($request);
$payment = $this->get('payum')->getPayment($token->getPaymentName());
try {
$payment->execute(new Sync($token));
} catch (RequestNotSupportedException $e) {}
$payment->execute($status = new GetHumanStatus($token));
/** #var OrderInterface $order */
$order = $status->getModel();
return $this->render('CustomBundle:Default:complete.html.twig', array(
'status' => $status->getValue(),
'order' => htmlspecialchars(json_encode(
array(
'client' => array(
'id' => $order->getClientId(), //<--- Error here
'email' => $order->getClientEmail(),
),
'number' => $order->getNumber(),
'description' => $order->getCurrencyCode(),
'total_amount' => $order->getTotalAmount(),
'currency_code' => $order->getCurrencyCode(),
'currency_digits_after_decimal_point' => $order->getCurrencyDigitsAfterDecimalPoint(),
'details' => $order->getDetails(),
),
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
)),
'paymentTitle' => ucwords(str_replace(array('_', '-'), ' ', $token->getPaymentName()))
));
}
}
Even if i use 'offline' payment option without Paypal Exress Checkout, i'm getting this error. Am i missing something maybe?

FuelPHP Sentry Insert Group on Regstration

I can't really find anything about this in the documentation.
I used Codeigniter a lot, and I used Ben Edmunds Ion auth mostly, and that was a bit easier for me, because there I was able to add a group insert function in the registration.
You can down vote this stupid question, but I can't find anything about this in the Sentry docs.
Here is my register code:
public function action_register()
{
$response = Response::forge();
// validation
$val = Validation::forge('registration');
$val->add_field('first_name', 'Username', 'required|trim|valid_string[alpha,spaces]');
//$val->add_field('first_name', 'Vezetéknév', 'required|');
$val->add_field('last_name', 'Keresztév', 'required');
$val->add_field('email', 'Email', 'required|valid_email');
$val->add_field('email_again', 'Email újra', 'required|valid_email|match_field[email]');
$val->add_field('password', 'Jelszó', 'required|min_length[5]');
$val->add_field('gender', 'Nemed', 'required');
$val->add_field('talent', 'Tehetséged', 'required');
$val->add_field('talent_level', 'Tehetségi szinted', 'required');
if($val->run()):
try
{
// register the user
$user = Sentry::user()->register(array(
'email' => Input::post('email'),
'password' => Input::post('password'),
'metadata' => array(
'first_name' => Input::post('first_name'),
'last_name' => Input::post('last_name'),
'gender' => Input::post('gender'),
'talent_level' => Input::post('talent_level'),
)
));
if($user):
//$email_data = array();
//echo Config::get('base_url'). "user/activate/". $user['hash'];
$email = Email::forge();
$email->from('my#email.me', Config::get('site_name'));
$email->to(Input::post('email'), Input::post('first_name'));
$email->subject('Regisztráció');
$email_data = array(
'name' => "Kedves " . Input::post('first_name'). "<br><br>",
'title' => "Üdvözöllek a ".Config::get('site_name')." oldalán" ."<br>",
'link' => 'Fiókod megerősítéséhez kérlek kattints ide'
);
$email->html_body(\View::forge('email/activation', array('email_data' => $email_data)));
$email->send();
$response->body(json_encode(array(
'status' => 'ok',
)));
else:
$data['errors'] = "error";
endif;
}
catch (SentryUserException $e)
{
$response->body(json_encode(array(
'status' => 'error',
'message' => array(
'email_taken' => $e->getMessage()
)
)));
}
else:
$response->body(json_encode(array(
'status' => 'error',
'message' => array(
'first_name' => $val->error('first_name') ? $val->error('first_name')->get_message() : null,
'last_name' => $val->error('last_name') ? $val->error('last_name')->get_message() : null,
'email' => $val->error('email') ? $val->error('email')->get_message() : null,
'email_again' => $val->error('email_again') ? $val->error('email_again')->get_message() : null,
'password' => $val->error('password') ? $val->error('password')->get_message() : null,
'gender' => $val->error('gender') ? $val->error('gender')->get_message() : null,
'talent' => $val->error('talent') ? $val->error('talent')->get_message() : null,
'talent_level' => $val->error('talent_level') ? $val->error('talent_level')->get_message() : null,
)
)));
endif;
return $response;
}
So my question is how can I make it save the user group selected?
Thank you.
This is taken from the Sentry Documentation; I think this is what you are after:
try
{
// option 1
$user->add_to_group(2);
// option 2
$user->add_to_group('editor');
}
catch (SentryUserException $e)
{
$errors = $e->getMessage(); // catch errors such as user already in group
}

Can't get Auth login to work with CakePHP 2.0

I'm trying to get a simple login form to work using CakePHP 2.0... just Auth, no ACLs for now.
I'm able to see the form and enter the email and password as they are in the database, but I just get returned to the form and the flash error message is displayed. Here is my code:
AppController:
class AppController extends Controller
{
function beforeFilter()
{
$this->Auth->userModel = 'Users';
$this->Auth->fields = array('username' => 'email', 'password' => 'password'); //have to put both, even if we're just changing one
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'hotels', 'action' => 'dashboard');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
}
}
login.ctp:
<?php
echo $this->Form->create('User', array('action' => 'login'));
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->end('Login');
?>
UsersController:
class UsersController extends AppController
{
var $name = 'Users';
var $helpers = array('Html','Form');
var $components = array('Auth','Session');
function beforeFilter()
{
$this->Auth->allow("logout");
parent::beforeFilter();
}
function index() { } //Redirects to login()
function login()
{
if ($this->Auth->login())
{
$this->redirect($this->Auth->redirect());
} else
{
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
function logout()
{
$this->redirect($this->Auth->logout());
}
}
?>
I appreciate any help with this. Thanks!
The "Invalid username or password, try again" error is displayed after you hit login?
There are a few things you should check:
• Is the output of $this->Auth->login() identical to the information in your database? Put debug($this->Auth->login()) to see the output in your login method after the form is submitted.
• Are the passwords correctly hashed in the database?
• Try making the AuthComponent available to all your controllers not just the UsersController.
• Not sure if this makes a difference, but call parent::beforeFilter(); before anything else in your controller's beforeFilter method.
EDIT:
Is see that you're trying to validate based on email and password. As a default AuthComponent expects a username and password. You have to explicitly state that you want the email and password to be validated by $this->Auth->login(). This comes from the 2.0 documentation:
public $components = array(
'Auth'=> array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
The fact that you're not seeing any SQL output is to be expected, I believe.
Also you must check if your field "password" in database is set to VARCHAR 50.
It happens to me that I was truncating the hashed password in DB and Auth never happened.
if you are not using defalut "username", "password" to auth, you cant get login
e.g., you use "email"
you should edit component declaration in your controller containing your login function:
$component = array('Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email', 'password' => 'mot_de_passe')
)
)
));
Becareful with cakephp's conventions. You should change this "$this->Auth->userModel = 'Users';" to "$this->Auth->userModel = 'User';" because User without plural is the Model's convention in cake. That worked for me and also becareful with the capital letters. it almost drived me crazy. Good luck.
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'Events',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'Users',
'action' => 'login',
'home'
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'username','password' => 'password')
)
)
)
);
Editing the component declaration in AppController did the trick for me. If you have the fields named other than "username" and "password" you should always specify them. In your case it would be
public $components = array(
'Auth' => array(
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish',
'fields' => array('username' => 'email','password' => 'password')
)
)
)
);
There is a bug in the cakephp tutorial.
$this->Auth->login() should be changed to
$this->Auth->login($this->request->data)