I'm studying contact from.
this is working great but one thing. email subject is always empty.
I wrote below code. Could someone teach me right code right?
Contact::create($request->all());
\Mail::send('mail', array(
'phone' => $request->get('phone'),
), function($message) use ($request){
$message->from($request->email);
$message->to('mail#mmmmail.com', 'subject title')->bcc('mail2#mmmmail.com')->subject($request->get('subject title'));
});
Related
$user_details=DB::table('table_users')
->select('table_users.*')
->where('id', $user_id)
->first();
\Mail::send('Invoice', array(
'name' => $user_details->name,
'email' => $user_details->email,
'subject' =>'Order is placed',
), function($message) use ($req){
$message->from($user_details->email);
$message->to('xyz#gmail.com', 'Admin')->subject('Order is Placed');
});
I am sending mail in laravel 5.7. My from email id in $user_details->email but it can not get in $message->from($user_details->email).
Since you're using annoymous function as the callback you need to pass the email in use() function as below:
use ($user_details){
you're not using $req neither it's defined anywhere you shared your code here so i think get rid of that if not needed.
I'm studing contact form with flash message.
Laravel Framework version is 7.15.0
I can display flash message using below Contoller code.
\Mail::send('mail', array(
'name' => $request->get('name'),
'email' => $request->get('email'),
'phone' => $request->get('phone'),
'subject' => $request->get('subject'),
'user_query' => $request->get('message'),
), function($message) use ($request){
$message->from($request->email);
$message->to('mymail#mydomain.com', 'Admin')->subject($request->get('subject'));
});
return back()->with('success', 'We have received your message and would like to thank you for writing to us.');
}
I would like to change the flash message as Japanese like below code.
return back()->with('送信完了', 'ありがとうございました');
however I couldn't get flash message.
I tried as dobule quote version below but it won't show message.
return back()->with("送信完了", "ありがとうございました");
Could you teach me what is wrong my code please?
try this code
return back()->with('success', 'ありがとうございました');
Hello I setup mailgun correctly. and did form contact us.
To send the message to my email by this code
public function send_contact_us()
{
$data = array(
'name' => Request::get('name'),'email'=>Request::get('email'),'subject'=> Request::get('subject'));
$client_m=Request::get('message');
$data_message=array('message_c'=>$client_m);
echo "we above MAIL";
Mail::send('emails.message',$data_message, function ($message)use ($data) {
$message->from($data['email'], 'E-SHOPPER');
$message->to("azharnabil013#yahoo.com")->subject($data['subject']);
});
return view('contact_us', array('title' => 'Welcome', 'description' => '', 'page' => 'contact_us','subscribe'=>'','sent'=>"Message has been sent successfuly"));
}
The code run correctly and this page display
But when I check my email I didn't find any message
I don't know why this problem .please, anyone help me.
Hello i'm new to laravel and still getting familiar with certain features, i would like to know how i can send an email from my laravel application without using gmail smtp settings. Like the way the mail function works in basic PHP. Is this possible? I have tried googling it but i have been unable to find a solution, they all use gmail.
Go to your app/config/mail.php
change driver, host and from
'driver' => 'mail',
'host' => '',
'from' => array('address' => 'us#example.com', 'name' => 'Laravel'),
or you can set 'from' within
Mail::send('emails.welcome', $data, function($message)
{
$message->from('us#example.com', 'Laravel');
$message->to('foo#example.com')->cc('bar#example.com');
});
I'm new to CakePhp, I'm using CakePhp 2.x.
I am probably going about solving the problem below the wrong way. And I just know I'm overlooked something real simple but,.....
I'm validating login details based on 'Between 5 to 15 characters' they are retuning errors as expected.
[The MODEL]
public $validate = array(
'username' => array(
'between' => array(
'rule' => array('between', 5, 15),
'message' => 'Between 5 to 15 characters'
)
),
'password' => array(
'rule' => array('minLength', '8'),
'message' => 'Minimum 8 characters long'
)
);
[The CONTROLLER]
public function login() {
if ($this->request->data) {
$this->User->set($this->request->data);
if ($this->User->validates() && $this->Auth->login()) {
if ($user = $this->Auth->user()) {
$this->render($this->Auth->redirect());
}else{
//??
}
}else{
$this->User->create();
pr($this->User->invalidFields());
$errors = $this->User->validationErrors;
$data = compact('errors');
$this->set('errors', $data);
$this->set('_serialize', array('errors'));
$this->Session->setFlash('Your username/password combination was incorrect');
}
}
}
So, the problem is, if the fields follow the rules in the model above even if the login details (the user) doesn't exist, no errors will be returned (no good). Would it be correct to add an other validation for this, adding another rule to check if that user actually exists? If so how!?
Or, do I work this into the controllers login function checking if the user exists? I'm a little confused now. Maybe I've been looking at the screen for too long.
Thanks.
Would it be correct to add an other validation for this, adding
another rule to check if that user actually exists? If so how!?
You can add as many rules as you want. In this case you want the rule "unique". Read this section of the book about data validation.
Or, do I work this into the controllers login function checking if the
user exists?
All data manipulation and validation should happen in the model layer of the MVC stack. So put everything into a model method and pass the post data to it and validate it there. You can put all logic into the controller to but that's stupid in terms of not following the MVC pattern. Models can be shared between shells and controllers for example, a controller not. Again you could instantiate a controller in a shell but doing all of this negates any benefit and idea the MVC pattern has. Also a model is competitively easy to test. And yes, you should unit test your code. Check how our users plugin is doing it for example.
You can specify multiple rules per field...
Follow this link to learn more about it...
http://book.cakephp.org/2.0/en/models/data-validation.html#multiple-rules-per-field
a sample code is given below
<?php
[IN The MODEL]
//the following code checks if the username is notempty, is a valid email and is it already taken or not...
public $validate = array(
'username' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Please enter a valid email.',
),
'email' => array(
'rule' => array('email'),
'message' => 'Please enter a valid email.',
),
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'This username has already been taken.'
)
)
);
?>