The following codes work and the email was sent out using my sendinblue API:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.sendinblue.com/v3/smtp/email');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \n \"sender\":{ \n \"name\":\"My name\",\n \"email\":\"[email protected]\"\n },\n \"to\":[ \n { \n \"email\":\"[email protected]\",\n \"name\":\"His name\"\n }\n ],\n \"subject\":\"Testing email on request\",\n \"htmlContent\":\"<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Sendinblue.</p></body></html>\"\n}");
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Api-Key: I removed API Key before posting this question';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
?>
But I would like to replace the sender name and email with variables but it didn't work out when I replace the
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \n \"sender\":{ \n \"name\":\"My name\",\n \"email\":\"[email protected]\"\n },\n \"to\":[ \n { \n \"email\":\"[email protected]\",\n \"name\":\"His name\"\n }\n ],\n \"subject\":\"Testing email on request\",\n \"htmlContent\":\"<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Sendinblue.</p></body></html>\"\n}");
with:
$myname = "My Name";
$myemail = "[email protected]";
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \n \"sender\":{ \n \"name\":$myname,\n \"email\":$myemail\n },\n \"to\":[ \n { \n \"email\":\"[email protected]\",\n \"name\":\"His name\"\n }\n ],\n \"subject\":\"Testing email on request\",\n \"htmlContent\":\"<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Sendinblue.</p></body></html>\"\n}");
Can anyone let me know where is the issue?
Sorry, I'm a beginner in coding... Thank you in advanced!