php code to send christmas custom gift cards

Here is an example of how you might use PHP to send custom Christmas gift cards using email:

<?php

// Replace with your own email address and name
$from = "your_email@example.com";
$from_name = "Your Name";

// Replace with the recipient's email address and name
$to = "recipient_email@example.com";
$to_name = "Recipient Name";

// Set the subject and message body
$subject = "Merry Christmas!";
$body = "Happy Holidays! Here is a custom gift card just for you:";

// Add the custom gift card image as an attachment
$file = "gift_card.jpg";
$file_type = "image/jpeg";
$file_name = "gift_card.jpg";

// Set the email headers
$headers = "From: " . $from_name . " <" . $from . ">" . "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

// Set the boundary string for the attachment
$boundary = uniqid("");

// Set the email body and attachment
$message = "--" . $boundary . "\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\r\n";
$message .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$message .= $body . "\r\n";
$message .= "--" . $boundary . "\r\n";
$message .= "Content-Type: " . $file_type . "; name=" . $file_name . "\r\n";
$message .= "Content-Disposition: attachment; filename=" . $file_name . "\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "X-Attachment-Id: " . rand(1000, 99999) . "\r\n\r\n";
$message .= chunk_split(base64_encode(file_get_contents($file)));

// Send the email
$success = mail($to, $subject, $message, $headers);

if ($success) {
  echo "The gift card was sent successfully!";
} else {
  echo "There was an error sending the gift card.";
}


This code will send an email to the recipient with a subject of "Merry Christmas!" and a message body of "Happy Holidays! Here is a custom gift card just for you:". It will also attach the image file "gift_card.jpg" to the email as an attachment.

You will need to replace the '$from', '$from_name', '&to', and '$to_name' variables with the appropriate values for your own email address and the recipient's email address. You will also need to specify the path to the gift card image file in the '$file' variable.

I hope this helps! Let me know if you have any questions.

Leave a Comment

Your email address will not be published. Required fields are marked *