Reputation: 2109
I'm currently using cPanel on my server side and i've tried all the tutorials online that show how to pipe all your emails to Laravel project, I did find one tutorial that works on Laravel 4 but unfortunately it didn't work for me on Laravel 5.0:
http://www.sitepoint.com/piping-emails-laravel-application/
I've set up my cPanel "default address" to a php handler file but since i'm working with Laravel I can't get this file to work with the app classes and do stuff for my customers (like send notifications, save email information on the database, etc...) please let me know if there is a nice clean way to accomplish that.
BTW, I need all the emails on this domain to go to my php handler not from one address only, because each one of my customers got his own email address
Upvotes: 2
Views: 2109
Reputation: 2109
I ended up creating a free account on mandrill and they are posting all my incoming emails to one of my routes.. than, I've created a controller to handle the incoming emails from mandrill and i can do whatever I need in there...Thats the best way to do It...I'm getting and processing emails in less than 2 seconds. That's amazing.
I've added the mandrill MX records to a subdomain of mine and now I gave all my customers an email address with this subdomain on it "[email protected]"
This is my route:
Route::post('inbound/message', 'MailController@inboundMessages');
and this is my controller example:
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
class MailController extends Controller
{
/**
* main function to receive incoming email from mandrill POST request
* @param JSON $request Mandrill Object in JSON format
* @return string
*/
public function inboundMessages(Request $request){
if(isset($request['mandrill_events'])){
$messageJson = json_decode($request['mandrill_events']);
$message = $messageJson[0]->msg;
$email = [
"to" => $message->email,
"from" => $message->from_email,
"name" => isset($message->from_name) ? $message->from_name : "No Name",
"subject" => isset($message->subject) ? $message->subject : "No Subject",
"content" => isset($message->text) ? $message->text : "",
"content_html" => isset($message->html) ? $message->html : ""
];
//do whatever you want with your $email
}
}
}
hope it helps :) Good luck
Upvotes: 7