<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use SendGrid;
use SendGrid\Mail\Mail;
use Illuminate\Support\Facades\Http;
class SendMail extends Mailable
{
public static function sendemail($to_data = "", $subject = "", $content = "")
{
$apiKey = env('MAIL_PASSWORD');
$email_from = env('MAIL_FROM_ADDRESS');
$email_from_name = env('MAIL_FROM_NAME');
$email = new Mail();
$email->setFrom($email_from, $email_from_name);
$email->setSubject($subject);
$email->addTo($to_data['to_email'], $to_data['name']);
// Add the rendered content to the email
$email->addContent("text/html", $content);
$sendgrid = new SendGrid($apiKey);
try {
$response = $sendgrid->send($email);
return true;
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."\n";
}
// $email = new Mail();
// $email->setFrom("[email protected]", "Sender Name");
// $email->setSubject("Subject of the Email");
// $email->addTo("[email protected]", "Recipient Name");
// $email->addContent("text/plain", "Hello, this is a test email!");
// $sendgrid = new SendGrid(env('SENDGRID_API_KEY'));
// try {
// $url = 'http://127.0.0.1:8000/';
// $response = Http::timeout(60)->get('http://127.0.0.1:8000');
// // Make the HTTP request with SSL certificate verification disabled
// $response = Http::withOptions(['verify' => false])->get($url);
// $response = $sendgrid->send($email);
// // Check if the email was sent successfully
// if ($response->statusCode() == 202) {
// echo "Email sent successfully!";
// } else {
// echo "Failed to send email: " . $response->body();
// }
// } catch (Exception $e) {
// echo 'Caught exception: ', $e->getMessage(), "\n";
// }
}
}
?>
|