Heim  >  Artikel  >  php教程  >  php发送邮件的问题详解,php发送邮件详解

php发送邮件的问题详解,php发送邮件详解

WBOY
WBOYOriginal
2016-06-13 09:00:11822Durchsuche

php发送邮件的问题详解,php发送邮件详解

php实现发送邮件,一般常用的是开源项目PHPMailer来实现,那么除此之外,有什么其他的好的项目吗?

解决方法:

使用SMTP协议来发送邮件吧

在CodeIgniter里面使用它内置的邮件类发送邮件

$this->load->library('email');

$to = "aa@bb.cc";
$subject = "test";
$message = "hello!";

$config["protocol"]   = "smtp";
$config["smtp_host"]  = "smtp.163.com";
$config["smtp_user"]  = "username@163.com";
$config["smtp_pass"]  = "password";
$config["mailtype"]   = "html";
$config["validate"]   = true;
$config["priority"]   = 3;
$config["crlf"]     = "/r/n";
$config["smtp_port"]  = 25;
$config["charset"]   = "utf-8";
$config["wordwrap"]   = TRUE;
$this->email->initialize($config);
$this->email->from('xxxx@163.com', 'xxxx');
$this->email->to($to);   
$this->email->subject($subject);
$this->email->message($message); 
$this->email->send();

这种方式发送邮件无需装任何软件,但是需要你写更多的代码,而且要对SMTP比较熟悉。

但是如果你不自己写,而是直接使用别人写好的现成的代码的话,那这种方法无疑是最省事的:

不需要自己搭建SMTP服务器,也不需要写很多的代码。

总结:

目前PHP自带的就是通过基于sendmail的mail()函数来发送邮件,不过前提是服务器上必须要安装sendmail,很多服务器空间商是没有安装sendmail邮件服务器的。所以这就有一定限制。

所以目前就有很多基于SMTP来发送邮件的开源组件,最出名的应该是是phpMailer,这个你已经知道了我就不多说了,我这里再说说其它的方法吧。
1、XPertMailer:这个也是开源的PHP发送邮件的组件,和phpMailer类似,也很方便,这里是它的官网(http://xpertmailer.sourceforge.net/),我亲自测试过,真得挺好的。

2、JMail:JMail是Windows下的组件,不过PHP支持通过COM来调用它,这也是一种解决方案吧,不过前提是Web Server如果在Windows运行倒是可以考虑,否则还是算了吧。

3、网上有很多人写的基于SMTP的mail类,也是可以用的,但是所支持功能就比较简单了。如果要求不高,也可以考虑。

4、这里还有20个比较出名开源PHP发送邮件的组件,本人没有一一测试过,不发表看法。你可以自己试试。在这里贴上地址:
介绍20个PHP发送邮件mail开源项目

以上所述就是本文的全部内容了,希望大家能够喜欢。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn