简体   繁体   English

如何使用 Mailgun CURL PhP 发送事务 email

[英]How to send transactional email using Mailgun CURL PhP

Answered below, Sharing my knowledge for future developers下面回答,为未来的开发者分享我的知识

How do I send transactional email via Mailgun如何通过 Mailgun 发送交易 email

I searched for solutions online, but did not find any solution online.我在网上搜索了解决方案,但没有在网上找到任何解决方案。

Feel free too add up your answers to help the community.随意添加您的答案以帮助社区。

<?php
//mailgun send transactional manil
$from_who = "YOUR COMPANY NAME HERE <do-not-reply@YOUR_DOMAIN NAME.com>";
$to_who = "receiver@example.com";
$subject= "Test Subject";
$mail_content = "Just testing some mailgun awesomeness";
$data = array(
'from' => $from_who ,
'to' => $to_who ,
'subject' => $subject,
'text' => $mail_content,
);
$post = http_build_query($data);
$versw = curl_init("https://api.mailgun.net/v3/mail.example.com/messages"); 
//the mail.example.com - THIS IS GOTTEN FROM YOUR MAILGUN DASHBOARD, it is the subdomain registered on Mailgun platform for sending emails
curl_setopt($versw, CURLOPT_POST, true);
curl_setopt($versw, CURLOPT_RETURNTRANSFER, true);
curl_setopt($versw, CURLOPT_USERPWD, "api:YOUR API KEY, ALSO GOTTEN ON MAILGUN DASHBOARD");
curl_setopt($versw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($versw, CURLOPT_POSTFIELDS, $post);
$run_curl = curl_exec($versw);
$run_clode = curl_close($versw);
//var_dump($run_curl);
$array_respo = json_decode($run_curl, true);
//var_dump($array_respo);
@$z_id = $array_respo["id"];
@$z_message = $array_respo["message"];
?>

Expected response in $z_id is your message id followed by your domain $z_id 中的预期响应是您的消息 ID,后跟您的域

Expected response in $z_message is Your message has been queued. $z_message 中的预期响应是您的消息已排队。 Message sent!消息已发送!

Happy Coding.快乐编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM