i want to send text not view by laravel mail , as i use simple form wth textarea to write the content of message , how to seend text or how to convert this text to view ....... thanks
public function sendmail(){
$sendmessage=Input::get('message');
//$messageView=View::make('messageview')->with('message',$sendmessage);
Mail::send($sendmessage, array('name'=>'hossam'),function($message){
$title=Input::get('title');
$mail=Input::get('mailsender');
$message->from($mail,'user');
$message->to('webdev11111#gmail.com','hossam gamal')->subject($title);
You can create an email view where the only thing it sends is the contents of a variable:
app/views/emails/nonview.blade.php
{{ $contents }}
Then, you can use this view whenever you want to send an email that doesn't have a view:
public function sendmail() {
$from = Input::get('mailsender');
$subject = Input::get('title');
// 'contents' key in array matches variable name used in view
$data = array(
'contents' => Input::get('message')
);
Mail::send('emails.nonview', $data, function($message) use ($from, $subject) {
$message->from($from, 'user');
$message->to('webdev11111#gmail.com','hossam gamal')->subject($subject);
});
}
Related
I'm using the Mail library in Laravel to send html email with custom data passed to a blade view.
The problem born when the mail has to render the html fetched from a row in the database which include a variable that i pass through the view.
This is my build function in my mailable class
public function build()
{
return $this->from('hello#test.it')
->view('view')
->with([
'url' => 'https://google.com',
'text' => $this->parameters->text,
]);
}
Then in the blade view:
<div>
{!! $text !!}
</div>
This is what the $text variable looks like:
<p>
<span>This is my text for the mail</span>
Click here to compile
</p>
The link href shoul contain the url variable value instead of not passing the variable name itself
A simple solution would be formating with php:
public function build()
{
return $this->from('hello#test.it')
->view('view')
->with([
'text' => str_replace('{{ $url }}','https://google.com',$this->parameters->text)
]);
}
I did not try by myself but you could make an attempt with Blade::compileString(), i.e.:
public function build()
{
return $this->from('hello#test.it')
->view('view')
->with([
'url' => 'https://google.com',
'text' => \Blade::compileString($this->parameters->text),
]);
}
I m new to laravel.i have table email_template and want to send mail to user when user forgot password.i m fetching content dynamically from database but i dont know how to pass it to mail function in laravel.
Mail::send($posts['email_template'], ['USER' =>$post['user] ], function($message)
{
$message->from('test#gmail.com')->subject('Welcome to laravel');
$message->to('test8#gmail.com');
});
where $posts['email_template'] is a content which i want to send and user is a variable which i want to replace in content
Mail::send('emails.template', ['user' => $user, 'data' => $data], function ($message) use ($user, $data) {
$message->from('test#gmail.com', 'Your Application');
$message->to('test8#gmail.com', $user->name)->subject('Welcome to laravel');
});
emails.template is your view - template.blade.php file - /resources/views/emails/template.blade.php
Now, in your view i.e emails.template, you can do:
{{ $user->name }}, {{ $data->address }}
You can Define
ADMIN_EMAIL and CC_EMAIL in the constant file in the config folder
$emailData = array(
'name'=>'toName',
'toEmail'=>$request->email
);
$this->sendEmail($emailData);
Email Function
function sendEmail($emailData){
$this->adminEmail = config('constant.ADMIN_EMAIL');
$this->ccEmail = config('constant.CC_EMAIL');
$this->toEmail = $emailData['toEmail'];
$this->emailTemplate = $emailData['emailTemplate'];
$data['emailInfo'] = array(
'name'=>$emailData['name']
);
Mail::send('emails.yourTemplate', $data, function ($message) {
//$message->attach($pathToFile);
$message->from($this->adminEmail, 'Laravel Email Test');
$message->to($this->toEmail)->cc($this->ccEmail);
});
}
$emails is an array but only shows me one email.
Also how to pass the email array into info_on_hand view?
$emails=$request['emails'][$i];
Mail::send('emails.info_on_hand', $data, function ($message) use($emails) {
$message->from('us#example.com', 'Name Company');
foreach($emails as $email):
$message->to($emails)->subject('Status: '.Input::get('desc').' With VIN# '.Input::get('vin').' is '.Input::get('status').'At Name');
endforeach;
});
So to send and pass the array of emails to the view and send it to them is like this
Guessing when you return just $emails it looks like this:
['test#example.com', 'test2#example.com','test3#example.com']
If so use this
$emails = $request['emails'];
Mail::send('emails.info_on_hand', ['emails' => $emails], function ($m) use ($emails) {
$m->from('youremail#eample.com', 'Name');
$m->to($emails);
$m->subject('Your Subject');
});
Another thing is that with the New GDPR laws don't think this is allowed?
I have a problem here.. i try to send email to multiple recepients. The recepients are from my database which name of table is subscribes the message error is like this
ErrorException in SimpleMessage.php line 297:
Illegal offset type
public function store_job(Request $request)
{
$this->validate($request, ['posisi' => 'required','persyaratan' => 'required','tanggung_jawab' => 'required']);
$tambah = new jobs(); //kita buat objek yang terhubung ke table JOBS
$tambah->posisi = $request['posisi'];
$tambah->persyaratan = $request['persyaratan'];
$tambah->tanggung_jawab = $request['tanggung_jawab'];
$tambah->kategori = $request['kategori'];
$tambah->save();
$anu = DB::table('subscribes')->select('email');
$data = array ('email'=>$anu);
Mail::send('emails.news', $data, function ($message) use ($request, $data) {
$message->from('stevanajja#gmail.com',$request->email);
$message->to($data['email'])->subject($request->posisi);;
});
return redirect()->to('/panel_admin/opportune');
}
please help as fast as possibble.. because i am a student, this is my homework for examination.
Here what I'am doing is declaring a new array $emails to store all email from database. By iterating the retrieved object anu, I am pushing the email to $emails and passing it to the to property of the mail.
$anu = DB::table('subscribes')->select('email')->get();
$emails=[];
foreach($anu as $a){
$emails[]=$a->email;
}
Mail::send('emails.news', $emails, function ($message) use ($request, $emails) {
$message->from('stevanajja#gmail.com',$request->email);
$message->to($emails)->subject($request->posisi);;
});
Illegal offset type errors occur when you attempt to access an array index using an object or an array as the index key.
This question should about match your effort.
How can i pass data from my Controller to my customized mail View ?
Here's my controller's send mail method :
$data = array($user->pidm, $user->password);
Mail::send('emails.auth.registration', $data , function($message){
$message->to(Input::get('Email'), 'itsFromMe')
->subject('thisIsMySucject');
Here's my emails.auth.registration View
<p>You can login into our system by using login code and password :</p>
<p><b>Your Login Code :</b></p> <!-- I want to put $data value here !-->
<p><b>Your Password :</b></p> <!--I want to put $password value here !-->
<p><b>Click here to login :</b> www.mydomain.com/login</p>
Thanks in advance.
Send data like this.
$data = [
'data' => $user->pidm,
'password' => $user->password
];
You can access it directly as $data and $password in email blade
$data = [
'data' => $user->pidm,
'password' => $user->password
];
second argument of send method passes array $data to view page
Mail::send('emails.auth.registration',["data1"=>$data] , function($message)
Now, in your view page use can use $data as
User name : {{ $data1["data"] }}
password : {{ $data1["password"] }}
for those using the simpleMail this might help :
$message = (new MailMessage)
->subject(Lang::getFromJson('Verify Email Address'))
->line(Lang::getFromJson('Please click the button below to verify your email address.'))
->action(Lang::getFromJson('Verify Email Address'), $verificationUrl)
->line(Lang::getFromJson('If you did not create an account, no further action is required.'));
$message->viewData['data'] = $data;
return $message;
The callback argument can be used to further configure the mail. Checkout the following example:
Mail::send('emails.dept_manager_strategic-objectives', ['email' => $email], function ($m) use ($user) {
$m->from('info#primapluse.com', 'BusinessPluse');
$m->to($user, 'admin')->subject('Your Reminder!');
});