通知短信+运营短信,5秒速达,支持群发助手一键发送🚀高效触达和通知客户 广告
## 使用[PHPMailer](https://code.google.com/a/apache-extras.org/p/phpmailer/) 经 PHPMailer 5.1 测试 PHP 提供了一个 [mail()](http://php.net/manual/zh/function.mail.php) 函数,看起来很简单易用。 不幸的是,与 PHP 中的很多东西一样,它的简单性是个幻象,因其虚假的表面使用它会导致严重的安全问题。 Email 是一组网络协议,比 PHP 的历史还曲折。完全可以说发送邮件中的陷阱与 PHP 的 mail() 函数一样多,这个可能会令你有点「不寒而栗」吧。 [PHPMailer](http://code.google.com/a/apache-extras.org/p/phpmailer/) 是一个流行而成熟的开源库,为安全地发送邮件提供一个易用的接口。 它关注可能陷阱,这样你可以专注于更重要的事情。 ## 示例 ~~~ <?php // Include the PHPMailer library require_once('phpmailer-5.1/class.phpmailer.php'); // Passing 'true' enables exceptions. This is optional and defaults to false. $mailer = new PHPMailer(true); // Send a mail from Bilbo Baggins to Gandalf the Grey // Set up to, from, and the message body. The body doesn't have to be HTML; // check the PHPMailer documentation for details. $mailer->Sender = 'bbaggins@example.com'; $mailer->AddReplyTo('bbaggins@example.com', 'Bilbo Baggins'); $mailer->SetFrom('bbaggins@example.com', 'Bilbo Baggins'); $mailer->AddAddress('gandalf@example.com'); $mailer->Subject = 'The finest weed in the South Farthing'; $mailer->MsgHTML('You really must try it, Gandalf!-Bilbo'); // Set up our connection information. $mailer->IsSMTP(); $mailer->SMTPAuth = true; $mailer->SMTPSecure = 'ssl'; $mailer->Port = 465; $mailer->Host = 'my smpt host'; $mailer->Username = 'my smtp username'; $mailer->Password = 'my smtp password'; // All done! $mailer->Send(); ?> ~~~