之前我们提供了如何使用 Mandrill 发送邮件的 PHP 代码片段,但是如果你不想使用第三方服务,那么可以使用下面的 PHP 代码片段。

  1. function send_mail($to,$subject,$body)
  2. {
  3. $headers = "From: KOONK\r\n";
  4. $headers .= "Reply-To: [email protected]\r\n";
  5. $headers .= "Return-Path: [email protected]\r\n";
  6. $headers .= "X-Mailer: PHP5\n";
  7. $headers .= 'MIME-Version: 1.0' . "\n";
  8. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  9. mail($to,$subject,$body,$headers);
  10. }
复制代码

用法:

  1. $subject = "This is a test mail";
  2. $body = "Hello World!";
  3. send_mail($to,$subject,$body);
  4. ?>
复制代码

发送邮件, PHP, mail


09-14 03:07