大家。
如何通过mailgun API服务正确发送邮件?
尝试这种方式:
$name = strip_tags(htmlspecialchars($_POST['name']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
// mailgun
function send_mailgun($email){
$config = array();
$config['api_key'] = "key-32312312-12312312312-8";
$config['api_url'] = "https://api.mailgun.net/v3/domain.com/messages";
$message = array();
$message['from'] = "test@gmail.com";
$message['to'] = $email;
$message['subject'] = "Eye-Catching Subject Line";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['api_url']);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "api:{$config['api_key']}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$message);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
send_mailgun('test@gmail.com');
但是,它不起作用。根本不发送电子邮件。使用Mailgun和php发送简单表单提交值的最简单/最快方法是什么?