php 发送邮件几种方式

一 使用php  mail 函数

在windows 下使用mail 函数进行发送,连接到邮件服务器,使用的是smtp 协议,但不支持esmtp 协议,即只能实现直投,不支持登录的转发,服务器地址是最终的邮件服务器地址,是在php.ini 中指定的。mall函数是ip是动态的,而且是私人的,没有权威容易被打成垃圾邮件。

1 安装smtp 服务,找一下这个软件  fstsmtp.exe

直接运行,使用netstat -an 查看25端口


2 配置php.ini

php 发送邮件几种方式_第1张图片

3 运行代码:

<?php
		$rec ="[email protected]";
		$subject ="say hello,to you!";
		$message = "hello,world!";
        var_dump(mail($rec ,$subject,$message));
    ?>

4 登录邮箱查看结果:

好吧,我们得承认被屏蔽了,被反垃圾邮件系统屏蔽了

php 发送邮件几种方式_第2张图片

php 发送邮件几种方式_第3张图片


二使用phpmailer 类库

下载地址:https://github.com/Synchro/PHPMailer

参考文档:http://www.kmwzjs.com/site/p-view51.html

注册163账号并开通smtp 服务

php 发送邮件几种方式_第4张图片

代码如下:

<?php
       require("./PHPMailer/class.phpmailer.php");
	   require("./PHPMailer/class.smtp.php");
	   $phpmailer = new  PHPMailer();
	   
	    $phpmailer->IsSMTP(); 
		$phpmailer->Host="smtp.163.com";
		$phpmailer->SMTPAuth=true;
		$phpmailer->Username="byfworld";
		$phpmailer->Password='18790529086';
		
		$phpmailer->From='[email protected]';
		$phpmailer->FromName='buyingfei888';
		
		$phpmailer->AddAddress('[email protected]','hello');
		$phpmailer->AddCC('[email protected]','wold');
		
		$phpmailer->Subject="我来试试";
		$phpmailer->Body='大虎';
	    echo	$phpmailer->Send() ? "ok ":"error";
		print_r($phpmailer->ErrorInfo);
    ?>




你可能感兴趣的:(php 发送邮件几种方式)