File: D:/HostingSpaces/SBogers104/angeliekly.nl/app/Komma/Mailers/MailService.php
<?php
namespace Komma\Mailers;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Schema;
use Komma\Mailers\Models\FormData;
use Komma\Mailers\Models\Mail;
class MailService extends Mailer
{
/**
* This method will send a form to the site admin
* after an user filled in the contact form
*
* @param $input
* @return bool
*/
public function sendContactForm($input)
{
$view = 'emails.contactForm';
//Get the to addres from the config
$to = \Config::get('mail.sendTo.address');
//Set the subject
$subject = \Lang::get('mail.contact.subject');
//Set the email addres as replyTo
$input['replyTo'] = $input['email'];
//Send the email
$this->sendTo($to, $subject, $view, $input);
return true;
}
public function saveMailToDatabase($data, $name = 'contact-form'){
array_forget($data, '_token');
array_forget($data, 'secretCode');
//check if all keys of data is in mail table else add them
foreach ($data as $key => $value){
if(!Schema::hasColumn('form_data', $key)){
Schema::table('form_data', function ($table) use ($key){
$table->text($key)->nullable();
});
}
}
//save new mail to DB
$mail = new FormData();
$mail->ip = \Request::ip();
$mail->browser = $_SERVER['HTTP_USER_AGENT'];
$mail->form_name = $name;
foreach ($data as $key => $value){
$mail->$key = $value;
}
$mail->save();
}
}