Home >Backend Development >PHP Tutorial >PHP code to send email using mandrill

PHP code to send email using mandrill

WBOY
WBOYOriginal
2016-07-25 08:42:381251browse

Mandrill is a powerful SMTP provider. Developers tend to use a third-party SMTP provider for better inbox delivery.

In the following function, you need to put "Mandrill.php" in the same folder as a PHP file, so that you can use TA to send emails.

  1. function send_email($to_email,$subject,$message1)
  2. {
  3. require_once 'Mandrill.php';
  4. $apikey = 'XXXXXXXXXX'; //specify your api key here
  5. $mandrill = new Mandrill($ apikey);
  6. $message = new stdClass();
  7. $message->html = $message1;
  8. $message->text = $message1;
  9. $message->subject = $subject;
  10. $message- >from_email = "blog@koonk.com";//Sender Email
  11. $message->from_name = "KOONK";//Sender Name
  12. $message->to = array(array("email" => $to_email));
  13. $message->track_opens = true;
  14. $response = $mandrill->messages->send($message);
  15. }
Copy code

"$apikey = 'XXXXXXXXXX'; //specify your api key here" Here you need to specify your API key (obtained from Mandrill account).

Syntax:

  1. $to = "abc@example.com";
  2. $subject = "This is a test email";
  3. $message = "Hello World!";
  4. send_email($ to,$subject,$message);
  5. ?>
Copy code

Send email, mandrill, PHP


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn