I tried sending an email of our app via Shopify's email processing PHP code

Topic summary

A developer is attempting to implement email functionality in their Shopify app using PHP code to send emails from the app admin to customers when specific events are triggered.

Current Issue:

  • The provided PHP code is not producing any response or working as expected
  • The code attempts to use Shopify’s Admin API email endpoint with cURL requests

Code Structure:

  • Uses Shopify store URL, access token, and email parameters (recipient, sender, subject, body)
  • Implements cURL to POST to the email sending endpoint
  • Includes error handling for response validation

Key Questions:

  • Seeking assistance to debug why the code isn’t functioning
  • Requesting confirmation whether this approach is correct or if Shopify provides alternative built-in features for admin-to-customer email functionality

Note: The posted code appears partially corrupted or reversed in sections, which may indicate a copy-paste error or encoding issue that could be contributing to the problem.

The discussion remains open with no responses yet.

Summarized with AI on November 14. AI used: claude-sonnet-4-5-20250929.

Here is the PHP code for the email processing.

I created this code for our app through Shopify’s email feature, intending to send emails from the app admin to customers’ mail. For example, when there’s an event triggered by the admin, an email needs to be sent from the admin’s email to the customer. However, it’s not yielding any response. Could you please assist me in resolving this issue for smooth functionality? Additionally, I’d like to confirm if this is the correct method or if Shopify provides this feature for such functionality.

// Replace with your actual Shopify store URL, access token, and other necessary details
$shopifyStoreUrl = ‘https://your-store.myshopify.com’;
$accessToken = ‘your-access-token’;
$recipientEmail = ‘recipient@example.com’;
$senderEmail = ‘sender@example.com’;
$emailSubject = ‘Subject of the Email’;
$emailBody = ‘Body of the Email’;

// Endpoint for sending emails
$endpoint = $shopifyStoreUrl . ‘/admin/api/2022-01/email/send.json’;

// Email payload
$emailData = [
‘email’ => [
‘subject’ => $emailSubject,
‘body’ => $emailBody,
‘to’ => $recipientEmail,
‘from’ => $senderEmail
]
];

// Initialize cURL session
$curl = curl_init($endpoint);

// Set cURL options
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($emailData),
CURLOPT_HTTPHEADER => [
‘Content-Type: application/json’,
'X-Shopify-Access-Token: ’ . $accessToken
]
]);

// Execute the cURL request
$response = curl_exec($curl);

// Check for errors
if ($response === false) {
echo 'Error sending email: ’ . curl_error($curl);
} else {
$responseData = json_decode($response, true);
if (isset($responseData[‘email’]) && $responseData[‘email’][‘status’] === ‘sent’) {
echo ‘Email sent successfully!’;
} else {
echo 'Failed to send email. Error: ’ . $response;
}
}

// Close cURL session
curl_close($curl);
?>

1 Like