Hello Reader's if you are looking to send emails via curl using PHP then this blog is helpful to you.
Curl is a tool which sent the data in forms to any other server with multiple data. So lets get started working on sending email with it.
Step 1:- Create a php code where you need to defined the user email address, email subject and its matter. Assign them in individual variables separately. This code will be written inside your controller and it will go like this:-
$subject = "This is an email test blog on findnerd";
$mail_message= "Hello this is blog on email via curl in findnerd";
$mail_message.='<br>Thanks, <br>Abhishek Tiwari';
$from = "email@example.com"
$to = "firstname.lastname@example.org"
$response = $this->mailmodel->sendEmail($to, $from, $subject, $mail_message);
In the code above you can set the target in var $to which is default as "email@example.com". Also you can type matter which you want to send in the email in var $subject.
Step2. Now create a new model and name it to mailmodel.php and its code will go like this:-
Now the function sendEmail() wil call by your controller this action in model will loads. And "$session = curl_init($request);" will load the curl. You must remember to check weather curl is enable or not in your server.
Now put the sendgrid credential to this curl params. And when the curl finished the server of sendgrid will send you a response in json format. This is the resonse code and status of your email request