用PHPMailer发送邮件

php中的mail函数使用起来虽然简单,配置却较为复杂。安装一个SMTP着实不易。在linux下,sendmail好像也不靠谱,今天163能收到信件,gmail收不到;明天163收不到了,gmail又可以收邮件了。

还是用PHPMailer吧,wordpress也用PHPMailer!看看它的代码:

 

	global $phpmailer;

	// (Re)create it, if it's gone missing
	if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) {
		require_once ABSPATH . WPINC . '/class-phpmailer.php';
		require_once ABSPATH . WPINC . '/class-smtp.php';
		$phpmailer = new PHPMailer();
	}

 

在PHPMailer README的 Installation 一节:

Copy class.phpmailer.php into your php.ini include_path. If you are
using the SMTP mailer then place class.smtp.php in your path as well.

 

而从wordpress的代码看,它直接用require_once来达到此目的,这样省去了配置php.ini的麻烦,有利于代码部署。

 

其他代码我就不贴了,README里的例子非常清晰了~

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值