Last active
May 30, 2025 17:19
-
-
Save mahircoding/580e39ca4c16cc78091bc797c0ab95d9 to your computer and use it in GitHub Desktop.
send mail with api mailtrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function kirim($v, $x, $y, $z) { | |
$curl = curl_init(); | |
curl_setopt_array($curl, [ | |
CURLOPT_URL => "https://send.api.mailtrap.io/api/send", | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_ENCODING => "", | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_POSTFIELDS => json_encode([ | |
'to' => [ | |
[ | |
'email' => $v, | |
'name' => $x | |
] | |
], | |
'from' => [ | |
'email' => '[email protected]', // Replace with your actual email | |
'name' => 'Jasa Trade' | |
], | |
'reply_to' => [ | |
'email' => '[email protected]', // Replace with your actual email | |
'name' => 'Reply' | |
], | |
'headers' => [ | |
'X-Message-Source' => 'dev.mydomain.com' // Replace with your actual domain web | |
], | |
'subject' => $y, | |
'text' => $z, | |
'html' => $z, | |
]), | |
CURLOPT_HTTPHEADER => [ | |
"Accept: application/json", | |
"Authorization: Bearer c271242f455e87fxxxxxxxxx", // Replace with your actual API token | |
"Content-Type: application/json" | |
], | |
]); | |
$response = curl_exec($curl); | |
$err = curl_error($curl); | |
curl_close($curl); | |
} | |
?> |
<?php
function kirim($v, $x, $y, $z) {
// Build payload dynamically
$payload = [
"Recipients" => [
"To" => [
"$x <$v>"
]
],
"Content" => [
"Body" => [
[
"ContentType" => "HTML",
"Content" => $z
]
],
"From" => "Jasa Trade <[email protected]>",
"ReplyTo" => "Jasa Trade <[email protected]>",
"Subject" => $y
],
"Options" => new stdClass() // Required for empty object
];
// cURL setup
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.elasticemail.com/v4/emails/transactional",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-ElasticEmail-ApiKey: "
],
]);
// Execute request
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
// Output result
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#<?php
function kirim($v, $x, $y, $z) {
}
?>