1.phpmailer,很好用,无论原生还是放到框架下,都没问题,phpmailer下载地址 https://github.com/PHPMailer/PHPMailer
- <?php
- header("content-type:text/html;charset=utf-8");
- include("class.phpmailer.php");
- include("class.smtp.php");
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->Host = "smtp.163.com";
- $mail->SMTPAuth = true;
- $mail->Username = "*********";
- $mail->Password = "*****";
- $mail->From = "******@163.com";
- $mail->FromName = "zph";
- $mail->CharSet = "utf-8";
- $mail->Encoding = "base64";
- $mail->AddAddress("******@163.com","toyou");
- $mail->AddReplyTo("******@163.com","wo");
-
-
-
- $mail->IsHTML(true);
-
- $subject="测试";
- $mail->Subject = $subject;
-
- $mail->Body = "
- <p>点击激活</p>
- <a href='#'>点击激活</a>
- ";
- $mail->AltBody ="text/html";
- if(!$mail->Send())
- {
- echo "邮件发送有误 <p>";
- echo "邮件错误信息: " . $mail->ErrorInfo;
- exit;
- }
- else {
- echo "邮件发送成功!<br />";
- }
2.当使用php原生mail()函数的时候,需要安装sendmail,linux一般已经安装sendmail,可以直接使用mail(),如果是windows需要先安装.
(smtp服务器搭建费事麻烦不好用^_^);
3.当使用ci框架的时候,如下
- public function sendemail()
- {
- $config = array('protocol'=>'smtp',
- 'smtp_host' => 'smtp.163.com',
- 'smtp_user' => 'yourname',
- 'smtp_pass' => '*****',
- 'smtp_port' => '25',
- '_smtp_auth' => TRUE,
- 'wordwrap' => TRUE,
- 'charset' => 'iso-8859-1'
-
- );
- $this->load->library('email', $config);
- $this->email->from('m13323262052@163.com', 'Your Name');
- $this->email->to('m13323262052@163.com');
- $this->email->subject('Email Test');
- $this->email->message('Testing the email class.');
- $this->email->send();
- }