File: D:/HostingSpaces/PDeckers/opelkapitan.nl/app/Komma/Mailers/MailService.php
<?php
namespace Komma\Mailers;
use Illuminate\Support\Facades\Input;
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;
}
/**
* This method will send a form to the site admin
* after an user filled in the contact form
*
* @param $input
* @return bool
*/
public function sendPopUpForm($input)
{
$view = 'emails.popUpForm';
//Get the to addres from the config
$to = \Config::get('mail.sendTo.address');
//Set the subject
$subject = \Lang::get('mail.popUp.subject');
//Set the email addres as replyTo
$input['replyTo'] = $input['email'];
//Send the email
$this->sendTo($to, $subject.' | '.$input['part_nr'], $view, $input);
return true;
}
/**
* Save input with form name to DB
*
* @param array $data
* @param string $name
*/
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('mails', $key)){
\Schema::table('mails', function ($table) use ($key){
$table->string($key)->nullable();
});
}
}
//save new mail to DB
$mail = new Mail();
$mail->ip = \Request::ip();
$mail->browser = $_SERVER['HTTP_USER_AGENT'];
$mail->form_name = $name;
foreach ($data as $key => $value){
$mail->$key = $value;
}
$mail->save();
}
}