Today, We want to share with you Laravel Send Mailgun Mail using PHP cURL.In this post we will show you Send mail with mailgun api by PHP CURL, hear for Mailgun Mail Sending api by PHP CURL we will give you demo and example for implement.In this post, we will learn about Laravel Access Controller method from another controller method with an example.
Laravel Send Mailgun Mail using PHP cURL
There are the Following The simple About Laravel Send Mailgun Mail using PHP cURL Full Information With Example and source code.
As I will cover this Post with live Working example to develop How to Send e-mail using Laravel PHP curl with Example, so the some major files and Directory structures for this example is following below.
- Global Setting Of the Mailgun
- Laravel custom Customsendmail
- controller from another controller
- Send mail with mailgun
Step 1 : Global Setting Of the Mailgun
.env file Global settings
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=captionPlacement DB_USERNAME=root DB_PASSWORD= MAIL_DRIVER=mailgun MAIL_HOST=smtp.mailgun.org MAIL_PORT=587 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=tls MAILGUN_DOMAIN=https://api.mailgun.net/v3/pakainfo.com/messages MAILGUN_SECRET=key-35ed9dd0c2ab5f2e8a24ed370Gl29a78526
Step 2: Create Laravel custom Customsendmail
app/Http/Controllers/Customsendmail.php
$param['from'],'to' => $param['to'], 'cc' => $param['cc'], 'bcc' => $param['bcc'], 'subject' => $param['subject'], 'html' => $param['message'])); curl_exec($ch); curl_close($ch); } }
Step 3 : Calling a controller from another controller
app/Http/Controllers/MemberController.php
Access Controller method from another controller in Laravel 5
middleware('auth'); $this->middleware('auth'); } public function index() { } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { request()->validate([ 'subject' => 'required', 'content' => 'required', 'team_id' => 'required|not_in:0', 'caption_id' => 'required|not_in:0', 'sub_caption_id' => 'required|not_in:0', 'g-recaptcha-response' => ['required'], ], [ 'team_id.required' => 'Team is required', 'caption_id.required' => 'Caption is required', 'g-recaptcha-response.required' => 'ReCaptcha required!', ]); $member = Members::create($request->all()); $message = "Your member #".$member->id." has been created. pakainfo is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development."; $live_member_id = $member->id; $from = 'Pakainfo Website'; $to = 'Member Placement'.trim($request->input('email')); $cc = 'Member Placement '; $bcc = 'Member Placement '; $subject = 'New member created #'.$live_member_id; $base_url = url('/members'); $member = strstr($request->input('email'), '@', true); $site_name = "Pakainfo"; $message_email = "Hi ".$member.",
"; $message_email .= "pakainfo is the most popular Programming & Web Development blog. $site_name.Our mission is to provide the best online resources on programming and web development. We deliver the useful and best tutorials for web professionals — developers, programmers, freelancers and site owners. number is: # $live_member_id
"; $message_email .= "Any visitors of this site are free to browse our tutorials, live demos and download scripts Member team at $site_name
"; $message_email .= "To view The full member or respond to the member Team, Please View Member to the caption member Placement.
"; $message_email .= "Best regrads
"; $message_email .= "Member Team Placement"; $data = array('from' => $from, 'to' => $to, 'cc' => $cc, 'cc' => $cc, 'bcc' => $bcc, 'subject' => $subject, 'message' => $message_email); Customsendmail::mail($data); if(Auth::guest()) { return redirect('memberactivemembers')->with('success',$message); } else { return redirect('createdata')->with('success',$message); } } }
Send mail with mailgun api by PHP CURL
In Customsendmail.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; class Customsendmail extends Controller { public function __construct() { } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public static function mail() { $from = 'Pakainfo Website'; $to = 'Member Placement '; $cc = 'Member Placement '; $bcc = 'Member Placement '; $subject = 'Member Team Placement'; $message = 'Member Team Placement .'; $mailgunsecret = env('MAILGUN_SECRET'); $mailguurl = env('MAILGUN_DOMAIN'); $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, 'api:'.$mailgunsecret); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_URL, $mailguurl); curl_setopt($ch, CURLOPT_POSTFIELDS, array('from' => $from,'to' => $to, 'cc' => $cc, 'bcc' => $bcc, 'subject' => $subject, 'html' => $message)); curl_exec($ch); curl_close($ch); } }
web.php
Route::get('mail', 'MemberController@mail');
MemberController.php
//Laravel Send Mailgun Mail using PHP cURL public static function mail() { return Customsendmail::mail(); }
Angular 6 CRUD Operations Application Tutorials
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Laravel Send Mailgun Mail using PHP cURL.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.