$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.
Related
my id field in a database named des_id
is there a specific way to change from table_name.id to table_name.des_id?
Route::post('Specific/uri', function (Request $request) {
$request->validate([
'destination_id' => 'required|exists:Database Name.Table Name,des_id',
'from' => 'required|numeric|min:0',
'to' => 'required|numeric|min:0',
]);
$destination_id = Destination::findOrFail($request->destination_id);
$from = $request->from;
$to = $request->to;
dispatch(new testJob($destination_id, $from, $to));
return response()->json([
'status' => true
]);
});
You won't be able to use the find or findOrFail if you don't use the standard naming convention for the identifier as laravel expects which is id. findOrFail expects the primary key to be named "id".
Because your primary key is named "des_id", for you to have the same exception behavior, you should use the where clause then end it with the firstOrFail() method which will offer a similar behavior to findOrFail.
You can learn more about findOrFail and firstOrFail here.
This is how you should perform that call to have the same Not Found Exception handling as findOrFail.
$destination_id = Destination::where('des_id','=',$request->destination_id)->firstOrFail();
i'm trying to make inquiry form where costumer fill up form then check the value on the checkbox then once they submit form will send email to me listing all the information the customer selected, now problem is i want to change this[event_id,requirement_id] instead of id replace it with name those two id parameter is from my two model listed below.
Model:
Event:[id,name]
Requirement:[id,name]
Controller:
public function store(Request $request)
{
$summary=[
'name' => $request->fullname,
'email' => $request->email,
'company' => $request->company,
'event' => $request->event_id,
'requirement' => $request->requirement_id
];
return $summary;
Mail::send('emails.contact-message',[
],function($mail) use($summary){
$mail->from('myemail#gmail.com', 'tester');
$mail->to('myemail#gmail.com')->subject('Contact Message');
});
return redirect()->back();
}
This is the result of my return request:
{"name":"myname","email":"myemail#gmail.com","company":"mycompany","event":["1","2"],"requirement":["1","2"]}
As you can see the array Event has value of 1 and 2 i wanted to replace it with its name output should be [Wedding,Birthday] i'm sorry for my bad english hope you understand me..
Well, you'd need to pull the name from your models.
The following should do the trick:
$events = App\Event::whereIn('id', $request->event_id)
->get()
->pluck('name')
->toArray();
$requirements = App\Requirement::whereIn('id', $request->requirement_id)
->get()
->pluck('name')
->toArray();
Obviously, replace name in the above example with the actual name field in your models. This is just an example.
$events and $requirements will both be an array containing the names matching the ids you are supplying in your request.
You also need to change your $summary array as follows:
$summary = [
'name' => $request->fullname,
'email' => $request->email,
'company' => $request->company,
'event' => $events
'requirement' => $requirements
];
Now, I'm building a contact form in Laravel. When I send message via the contact form, I'm taking messages by myself. And that message is appearing in Gmail spam folder.
I'm using my mail service which is connected to my domen. I'm forwarding messages to my gmail account.
My config:
namespace App\Http\Controllers;
use App\SendMessage;
use App\Mail\SendEmail;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\Http\Controllers\Controller;
use Session;
class SendMessageController extends Controller
{
public function store(Request $request) {
$this->validate($request, [
"email" => "required|email",
"message" => "min:10",
"subject" => "min:3"
]);
$data = array(
'email' => $request->email,
'name' => $request->name,
'company' => $request->company,
'subject' => $request->subject,
'bodyMessage' => $request->message
);
Mail::send('emails.contact', $data, function ($message) use ($data) {
$message->from($data['email']);
$message->to('audit#auditors.uz');
$message->subject($data['subject']);
});
Session::flash("success", "Ваше сообщение успешно отправлено.");
return back();
}
}
It is my view:
<div>
<p>{{ $bodyMessage }}</p>
</div>
<p> {{ $email }} tomonidan jo'natildi</p>
If somebody knows, why it is happening. Please, help me, I'm going crazy right now.
This is nothing to do with Laravel, this is because you are trying to send an email via your email server from a completely different user and domain. This would get it flagged up pretty easily. Basically, it looks like you are trying to spoof emails if website1.com is sending an email from user1#hotmail.com. It is not a genuine email from the server.
I would recommend using a generic email address on your server to send from, e.g. contact#mysite.com and include the user's email address in the reply-to field.
Currently updating Laravel from v5.2 to 5.5 and can't figure out how I get the "unique" rule working on update.
This is my rule that works nice on Laravel 5.2
public function rules()
{
$retVal = [
'username' => 'required|alpha_dash|min:4|max:30',
'password' => 'min:6|confirmed',
'password_confirmation' => 'min:6',
'email' => 'required|email|unique:users,email,' . $user->id,
'roles_list' => 'required',
];
if (stristr($this->get('username'), '#'))
{
$retVal['username'] = 'required|email';
}
return $retVal;
}
But now in Laravel 5.5 I get always an "email unique"-error on update. When I type in the user-id manually it works. Like described in the Laravel docs it should work:
https://laravel.com/docs/5.5/validation#form-request-validation
I have no clue how to get the $user object accessible in my form request.
Thank you very much in advance for assist !
Your $user variables seems null.
If you're trying to retrieve the currently authenticated user in your Request class, you can try this:
$user = $this->user();
Next, you have to change your email rules a bit:
'email' => 'required|email|unique:users,email,' . ($user ? $user->id : 0),
I am running the following code (I've hidden ID's) to update a subscriber's email address in a MailChimp list:
$mailchimp->patch('lists/1234567/members/' . md5('test#test.com'), [
'email_address' => 'new-email#newtest.com',
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => 'Ben',
'LNAME' => 'Sinclair',
),
]);
It does not seem to work. I do not receive any errors, it just does nothing.
How do you update an email address in a MailChimp list using API V3?
http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#edit-patch_lists_list_id_members_subscriber_hash
Currently, the email address is a parameter (read only = false) in the PUT method (.../3.0/lists/{listId}/members/{md5}) that allows to change the email address of the subscriber.
I'm sending the new email in the body and MERGE0 (EMAIL) tag but using the md5 from the previous email. It is changing the email correctly.
You can change the email address when you make the request
PUT https://usx.api.mailchimp.com/3.0/lists/{list_id}/members/{subscriber_hash}
and the body was this:
{"email_address": "new#email.com"}
$List = 123456;
$subscriber_hash = md5("old#email.com")
$data = array('email_address' => "new#email.com" );
$result = $mailchimp->put("lists/$List/members/$subscriber_hash", $data);