DIEA
我不推荐Pear Mail。它自2010年以来一直没有更新。还阅读源文件; 源代码几乎已过时,以PHP 4风格编写,并发布了许多错误/错误(谷歌)。我正在使用Swift Mailer。Swift Mailer集成到用PHP 5编写的任何Web应用程序中,提供灵活而优雅的面向对象的方法来发送具有多种功能的电子邮件。使用SMTP,sendmail,postfix或您自己的自定义传输实现发送电子邮件。支持需要用户名和密码和/或加密的服务器。在不剥离请求数据内容的情况下防止标头注入攻击。发送符合MIME的HTML /多部分电子邮件。使用事件驱动的插件来自定义库。处理内存使用率低的大附件和内联/嵌入图像。它是一个免费的开源您可以下载Swift Mailer并上传到您的服务器。(功能列表从所有者网站复制)。Gmail SSL / SMTP和Swift Mailer的工作示例就在这里......// Swift Mailer Libraryrequire_once '../path/to/lib/swift_required.php';// Mail Transport$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
->setUsername('username@gmail.com') // Your Gmail Username
->setPassword('my_secure_gmail_password'); // Your Gmail Password// Mailer$mailer = Swift_Mailer::newInstance($transport);// Create a message$message = Swift_Message::newInstance('Wonderful Subject Here')
->setFrom(array('sender@example.com' => 'Sender Name')) // can be $_POST['email'] etc...
->setTo(array('receiver@example.com' => 'Receiver Name')) // your email / multiple supported.
->setBody('Here is the message itself. It can be text or
HTML
.', 'text/html');// Send the messageif ($mailer->send($message)) {echo 'Mail sent successfully.';} else {
echo 'I am sure, your configuration are not correct. :(';}我希望这有帮助。快乐的编码...... :)