资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php数据库转发邮件,php发送邮箱

php表单数据发送到指定邮件

首先,我们需要去Github(网页链接)下载完整的SwiftMailer

创新互联公司服务项目包括始兴网站建设、始兴网站制作、始兴网页制作以及始兴网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,始兴网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到始兴省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

这里主要使用到的是下载解压后lib文件夹里的内容,然后需要一些配置项,为方便管理和修改,此处我们写一个配置文件config.php,来进行配置,此处以QQ邮箱为例,配置项如下:

然后自定义一个函数sendMail(函数里的C是thinkphp里获取配置文件的方法,自己在不是tp里的话使用直接require就可以了)

然后在相关代码里使用调用sendMail发送邮件,这里以ThinkPHP里的controller为例子,使用方法如下:

发送成功后显示 ‘Done!’:

然后就可以去邮箱查看是否收取到邮件咯。

就是这么简单。

参考:网页链接

怎么利用php发送邮件求详细教程

PHP虽然提供了mail()函数,但并不好用,而PHPMailer是一个不错的邮件发送工具,接下来将详细介绍,需要了解的朋友可以参考下:

本人使用wamp集成开发环境,Apache2.4.4, Mysql5.6.12 , php5.4.12.开始的时候使用mail()发送邮件,更改配置始终无法成功,了解到mail()函数使用需要sendmail程序。又下载了sendmail程序扩展包。按照网上的说法也改好了php.ini和sendmail.ini。使用foxmail 7.1创建了自己的qq邮箱账户,开启了POP3/SMTP服务,更改发件服务器为POP3,使用和收件服务器相同的身份验证,结果还是报错:Warning: mail(): SMTP server response: 503 Error: need EHLO and AUTH first ! in F:\PHP\wamp\www\mail.php on line 8。以下是使用mail()函数发送邮件的php代码:

[php] view plain copy

span style="font-size:14px"?php

$to = "757006080@qq.com";

$subject = "Test mail";

$message = "Hello! This is a simple email message.";

$from = "757006080@qq.com";

$headers = "From: $from";

$send=mail($to,$subject,$message,$headers);

if($send)

echo "Mail Sent";

else

echo "Sorry,mail sent failed!"

?/span

在CSDN论坛上发现phpmailer可以方便快捷的发送邮件,以下写出详细使用教程:

1.需要下载PHPMailer文件包,(点击打开链接)

2.确认你的服务器已经系统支持socket,通过phpinfo()查看是否支持socket;

3.把文件解压到你的WEB服务器目录下,就可以使用PHPMailer发送邮件了。

以下为前台表单php代码:

[php] view plain copy

span style="font-size:14px"html

body

h3phpmailer Unit Test/h3

请你输入font color="#FF6666"收信/font的邮箱地址:

form name="phpmailer" action="testemail.php" method="post"

input type="hidden" name="submitted" value="1"/

邮箱地址: input type="text" size="50" name="to" /

br/

input type="submit" value="发送"/

/form

/body

/html /span

以下为后台程序:

[php] view plain copy

?php

/**

* Simple example script using PHPMailer with exceptions enabled

* @package phpmailer

* @version $Id$

*/

header("content-type:text/html;charset=utf-8");

ini_set("magic_quotes_runtime",0);

require('class.phpmailer.php');

try {

$mail = new PHPMailer(true); //New instance, with exceptions enabled

//$body = file_get_contents('contents.html');

//$body = preg_replace('/\\\\/','', $body); //Strip backslashes

$to = $_POST['to'];

$mail-CharSet="GB2312";//设置邮件字符编码否则邮件会乱码

$mail-Encoding="base64";

$mail-IsSMTP(); // tell the class to use SMTP

$mail-SMTPAuth = true; // enable SMTP authentication

$mail-Port = 25; // set the SMTP server port

$mail-Host = "smtp.qq.com"; // SMTP server

$mail-Username = "757006080@qq.com"; // SMTP server username

$mail-Password = "000000000000"; // SMTP server password

//$mail-IsSendmail(); // tell the class to use Sendmail

$mail-AddReplyTo("757006080@qq.com","han qing");

$mail-From = "757006080@qq.com";

$mail-FromName = "han qing";

//$to = "hanqing757@gmail.com";

$mail-AddAddress($to);

$mail-Subject =$mail-Subject = "=?utf-8?B?" . base64_encode("First PHPMailer Message") . "?=";

$mail-Body = "h1phpmailer演示/h1 这是用PHPMAILER发的第一份邮件,从QQ邮箱发到Google邮箱.";

$mail-AddAttachment("F:/myloe.jpg");

$mail-AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail-WordWrap = 80; // set word wrap

//$mail-MsgHTML($body);

$mail-IsHTML(true); // send as HTML

$mail-Send();

echo 'Message has been sent.';

} catch (phpmailerException $e) {

echo $e-errorMessage();

}

?

php如何发送邮件

你好,用这个邮件类,需要在调用时,填写一个smtp服务器和你的用户名密码。

?php

set_time_limit(600);

/*

* 邮件发送类

*/

class smail {

//您的SMTP 服务器供应商,可以是域名或IP地址

var $smtp = "";

//SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证,如不清楚请与你的smtp 服务商联系。

var $check = 1;

//您的email帐号名称

var $username = "";

//您的email密码

var $password = "";

//此email 必需是发信服务器上的email

var $s_from = "";

/*

* 功能:发信初始化设置

* $from 你的发信服务器上的邮箱

* $password 你的邮箱密码

* $smtp 您的SMTP 服务器供应商,可以是域名或IP地址

* $check SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证

*/

function smail ( $from, $password, $smtp, $check = 1 ) {

if( preg_match("/^[^\d\-_][\w\-]*[^\-_]@[^\-][a-zA-Z\d\-]+[^\-](\.[^\-][a-zA-Z\d\-]*[^\-])*\.[a-zA-Z]{2,3}/", $from ) ) {

$this-username = substr( $from, 0, strpos( $from , "@" ) );

$this-password = $password;

$this-smtp = $smtp ? $smtp : $this-smtp;

$this-check = $check;

$this-s_from = $from;

}

}

/*

* 功能:发送邮件

* $to 目标邮箱

* $from 来源邮箱

* $subject 邮件标题

* $message 邮件内容

*/

function send ( $to, $from, $subject, $message ) {

//连接服务器

$fp = fsockopen ( $this-smtp, 25, $errno, $errstr, 60);

if (!$fp ) return "联接服务器失败".__LINE__;

set_socket_blocking($fp, true );

$lastmessage=fgets($fp,512);

if ( substr($lastmessage,0,3) != 220 ) return "错误信息1:$lastmessage".__LINE__;

//HELO

$yourname = "YOURNAME";

if($this-check == "1") $lastact="EHLO ".$yourname."\r\n";

else $lastact="HELO ".$yourname."\r\n";

fputs($fp, $lastact);

$lastmessage == fgets($fp,512);

if (substr($lastmessage,0,3) != 220 ) return "错误信息2:$lastmessage".__LINE__;

while (true) {

$lastmessage = fgets($fp,512);

if ( (substr($lastmessage,3,1) != "-") or (empty($lastmessage)) )

break;

}

//身份验证

if ($this-check=="1") {

//验证开始

$lastact="AUTH LOGIN"."\r\n";

fputs( $fp, $lastact);

$lastmessage = fgets ($fp,512);

if (substr($lastmessage,0,3) != 334) return "错误信息3:$lastmessage".__LINE__;

//用户姓名

$lastact=base64_encode($this-username)."\r\n";

fputs( $fp, $lastact);

$lastmessage = fgets ($fp,512);

if (substr($lastmessage,0,3) != 334) return "错误信息4:$lastmessage".__LINE__;

//用户密码

$lastact=base64_encode($this-password)."\r\n";

fputs( $fp, $lastact);

$lastmessage = fgets ($fp,512);

if (substr($lastmessage,0,3) != "235") return "错误信息5:$lastmessage".__LINE__;

}

//FROM:

$lastact="MAIL FROM: ". $this-s_from . "\r\n";

fputs( $fp, $lastact);

$lastmessage = fgets ($fp,512);

if (substr($lastmessage,0,3) != 250) return "错误信息6:$lastmessage".__LINE__;

//TO:

$lastact="RCPT TO: ". $to ." \r\n";

fputs( $fp, $lastact);

$lastmessage = fgets ($fp,512);

if (substr($lastmessage,0,3) != 250) return "错误信息7:$lastmessage".__LINE__;

//DATA

$lastact="DATA\r\n";

fputs($fp, $lastact);

$lastmessage = fgets ($fp,512);

if (substr($lastmessage,0,3) != 354) return "错误信息8:$lastmessage".__LINE__;

//处理Subject头

$head="Subject: $subject\r\n";

$message = $head."\r\n".$message;

//处理From头

$head="From: $from\r\n";

$message = $head.$message;

//处理To头

$head="To: $to\r\n";

$message = $head.$message;

//加上结束串

$message .= "\r\n.\r\n";

//发送信息

fputs($fp, $message);

$lastact="QUIT\r\n";

fputs($fp,$lastace);

fclose($fp);

return 0;

}

}

// 发送示例

// 只需要把这部分改成你的信息就行

$sm = new smail( "用户名", "密码", "发件smtp服务器" );

$end = $sm-send( "收件人", "发件人(可以伪造哦)", "标题", "内容" );

if( $end ) echo $end;

else echo "发送成功!$x";

?


文章名称:php数据库转发邮件,php发送邮箱
网页URL:http://cdkjz.cn/article/hcjsoh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220