11
08月
2015
2. 使用 mandrill 发送邮件
Mandrill 是一款强大的 SMTP 提供器。开发者倾向于使用一个第三方 SMTP provider 来获取更好的收件交付。
下面的函数中,你需要把 “Mandrill.php” 放在同一个文件夹,作为 PHP 文件,这样就可以使用TA来发送邮件。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
function send_email( $to_email , $subject , $message1 )
{
require_once 'Mandrill.php' ;
$apikey = 'XXXXXXXXXX' ; //specify your api key here
$mandrill = new Mandrill( $apikey );
$message = new stdClass();
$message ->html = $message1 ;
$message ->text = $message1 ;
$message ->subject = $subject ;
$message ->from_email = "blog@koonk.com" ; //Sender Email
$message ->from_name = "KOONK" ; //Sender Name
$message ->to = array ( array ( "email" => $to_email ));
$message ->track_opens = true;
$response = $mandrill ->messages->send( $message );
}
|
“$apikey = 'XXXXXXXXXX'; //specify your api key here”这里需要你指定你的 API 密钥(从 Mandrill 账户中获得)。
语法:
1
2
3
4
5
6
|
<?php
$to = "abc@example.com" ;
$subject = "This is a test email" ;
$message = "Hello World!" ;
send_email( $to , $subject , $message );
?>
|
为了达到最好的效果,最好按照 Mandrill 的教程去配置 DNS。
特殊说明,本文版权归 ning个人博客 所有带原创标签请勿转载,转载请注明出处.