Send Email To Customer as soon as he purchase the product. Here is the code sample
<code>$response = Http::withHeaders([
'Authorization' => 'Basic ' . base64_encode('apikey:' . env('MAILCHIMP_TRANSACTIONAL_APIKEY')),
'Content-Type' => 'application/json',
])->post('https://us12.api.mailchimp.com/3.0/messages/send', [
'message' => [
'subject' => 'Purchase Confirmation Email',
'from_email' => '[email protected]',
'to' => [
['email' => $customerEmail],
],
'html' => view('emails.purchase_confirmation', compact('orderDetails', 'products'))->render(),
],
]);
</code>
<code>$response = Http::withHeaders([
'Authorization' => 'Basic ' . base64_encode('apikey:' . env('MAILCHIMP_TRANSACTIONAL_APIKEY')),
'Content-Type' => 'application/json',
])->post('https://us12.api.mailchimp.com/3.0/messages/send', [
'message' => [
'subject' => 'Purchase Confirmation Email',
'from_email' => '[email protected]',
'to' => [
['email' => $customerEmail],
],
'html' => view('emails.purchase_confirmation', compact('orderDetails', 'products'))->render(),
],
]);
</code>
$response = Http::withHeaders([
'Authorization' => 'Basic ' . base64_encode('apikey:' . env('MAILCHIMP_TRANSACTIONAL_APIKEY')),
'Content-Type' => 'application/json',
])->post('https://us12.api.mailchimp.com/3.0/messages/send', [
'message' => [
'subject' => 'Purchase Confirmation Email',
'from_email' => '[email protected]',
'to' => [
['email' => $customerEmail],
],
'html' => view('emails.purchase_confirmation', compact('orderDetails', 'products'))->render(),
],
]);
And here is my html code for email
<code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Purchase Confirmation</title>
</head>
<body>
<h1>Purchase Confirmation</h1>
<p>Dear {{ $order['firstName'] }} {{ $order['lastName'] }},</p>
<p>Thank you for your purchase!</p>
<h2>Order Details:</h2>
<p><strong>Order ID:</strong> {{ $order['orderId'] }}</p>
<p><strong>Total Amount:</strong> ${{ $order['totalAmount'] }}</p>
<!-- Include other order details here -->
<h2>Business Details:</h2>
<p><strong>Business Name:</strong> {{ $order['businessName'] }}</p>
<p><strong>Business Nature:</strong> {{ $order['businessNature'] }}</p>
<!-- Include other business details here -->
<h2>Customer Details:</h2>
<p><strong>Customer Email:</strong> {{ $order['customerEmail'] }}</p>
<p><strong>Customer Phone:</strong> {{ $order['customerPhone'] }}</p>
<!-- Include other customer details here -->
<h2>Product Details:</h2>
@foreach ($products as $product)
<p><strong>Product Name:</strong> {{ $product['productName'] }}</p>
<p><strong>Product Price:</strong> ${{ $product['productPrice'] }}</p>
<!-- Include other product details here -->
@endforeach
</body>
</html>
</code>
<code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Purchase Confirmation</title>
</head>
<body>
<h1>Purchase Confirmation</h1>
<p>Dear {{ $order['firstName'] }} {{ $order['lastName'] }},</p>
<p>Thank you for your purchase!</p>
<h2>Order Details:</h2>
<p><strong>Order ID:</strong> {{ $order['orderId'] }}</p>
<p><strong>Total Amount:</strong> ${{ $order['totalAmount'] }}</p>
<!-- Include other order details here -->
<h2>Business Details:</h2>
<p><strong>Business Name:</strong> {{ $order['businessName'] }}</p>
<p><strong>Business Nature:</strong> {{ $order['businessNature'] }}</p>
<!-- Include other business details here -->
<h2>Customer Details:</h2>
<p><strong>Customer Email:</strong> {{ $order['customerEmail'] }}</p>
<p><strong>Customer Phone:</strong> {{ $order['customerPhone'] }}</p>
<!-- Include other customer details here -->
<h2>Product Details:</h2>
@foreach ($products as $product)
<p><strong>Product Name:</strong> {{ $product['productName'] }}</p>
<p><strong>Product Price:</strong> ${{ $product['productPrice'] }}</p>
<!-- Include other product details here -->
@endforeach
</body>
</html>
</code>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Purchase Confirmation</title>
</head>
<body>
<h1>Purchase Confirmation</h1>
<p>Dear {{ $order['firstName'] }} {{ $order['lastName'] }},</p>
<p>Thank you for your purchase!</p>
<h2>Order Details:</h2>
<p><strong>Order ID:</strong> {{ $order['orderId'] }}</p>
<p><strong>Total Amount:</strong> ${{ $order['totalAmount'] }}</p>
<!-- Include other order details here -->
<h2>Business Details:</h2>
<p><strong>Business Name:</strong> {{ $order['businessName'] }}</p>
<p><strong>Business Nature:</strong> {{ $order['businessNature'] }}</p>
<!-- Include other business details here -->
<h2>Customer Details:</h2>
<p><strong>Customer Email:</strong> {{ $order['customerEmail'] }}</p>
<p><strong>Customer Phone:</strong> {{ $order['customerPhone'] }}</p>
<!-- Include other customer details here -->
<h2>Product Details:</h2>
@foreach ($products as $product)
<p><strong>Product Name:</strong> {{ $product['productName'] }}</p>
<p><strong>Product Price:</strong> ${{ $product['productPrice'] }}</p>
<!-- Include other product details here -->
@endforeach
</body>
</html>
I want that my laravel 9 code send custom email to customer as soon he purchased the product i have mailchimp api key and i want a transactional email.