新手想做一个PHP的表单提交发送到指定邮箱,请高手指教?

作者&投稿:本琛 (若有异议请与网页底部的电邮联系)
跪求php高手指教。。 做一个注册页面,确定以后系统会向你填写的邮箱地址发一封邮件。。 这个该咋弄??~

50块,给你做
QQ:15624575

您好,
提交格式一般默认为表单格式,只要你的html里form的method="post";就行了,
想插入到mysql里面,你的php文档里首先要
$POST获取表单的提交的数据
连接数据库(输入用户名,密码)
转到数据库名,表单名
往里面插入数据(规范格式)
关闭连接
返回需要返回的提示

首先包含一个邮件发送类 require("sendMail.php");
然后你要有一个发送邮件的服务器(可以到163随意注册个,例如注册的是aa@163.com,密码是aa123),然后是发送邮件的代码,我给你一个我用的例子
$smtpserver = "smtp.163.com"; //你选择的SMTP服务器
$smtpserverport =25; //SMTP服务器端口
$smtpusermail = "aa@163.com"; //SMTP服务器的用户邮箱
$smtpemailto = "bb@qq.com"; //收件箱
$smtpuser = "aa@163.com"; //SMTP服务器的用户帐号
$smtppass = "aa123"; //SMTP服务器的用户密码
$MailBody="姓名:".$_POST['Name'];//邮件内容(如你提交的表单姓名为Name)
$mailsubject=@iconv("UTF-8", "gb2312", "XX网站-问题提交");//如果你页面为UTF-8,这里还要转码一下
$mailbody = $MailBody; //邮件内容
$mailtype = "HTML"; //邮件格式(HTML/TXT),TXT为文本邮件
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//true表示使用身份验证,否则不使用身份验证.
$smtp->debug = FALSE; //是否显示发送的调试信息 TRUE发送 FALSE不发送
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);

sendMail.php代码:
class smtp
{
/* Public Variables */
var $smtp_port; //邮件服务器端口
var $time_out; //超时时间
var $host_name; //主机名称
var $log_file; //日志文件
var $relay_host; //
var $debug;
var $auth;
var $user; //用户名
var $pass; //密码
var $sock;
/* Constractor */
function smtp($relay_host, $smtp_port,$auth,$user,$pass)
{
// echo $relay_host." ".$smtp_port." ".$auth." ".$user." ".$pass;
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30;//is used in fsockopen()
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
$this->host_name = "localhost";//is used in HELO command
$this->log_file = "";
$this->sock = FALSE;
}

/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));
if ($cc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}
if ($bcc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
}
else {
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
return $sent;
}

/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo)) {
return $this->smtp_error("sending HELO command");
}
if($this->auth){
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
return $this->smtp_error("sending HELO command");
}
}
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("sending DATA command");
}
if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom()) {
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}
if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("sending QUIT command");
}
return TRUE;
}

function smtp_sockopen($address)
{
if ($this->relay_host == "") {
return $this->smtp_sockopen_mx($address);
} else {
return $this->smtp_sockopen_relay();
}
}

function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;
}

function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);
if (!@getmxrr($domain, $MXHOSTS)) {
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host) {
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}

function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}

function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}

function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");
if (!ereg("^[23]", $response)) {
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}

function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}

function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}

function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "") {
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}

function strip_comment($address)
{
$comment = "\([^()]*\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}
return $address;
}

function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);
return $address;
}

function smtp_debug($message)
{
if ($this->debug) {
//echo $message;
}
}
}

不明白你的意思,到底要发到哪里,邮箱?数据库?如果是邮箱的话,前台收集好数据,然后用php自带的邮件类就可以,不关数据库的事。如果是数据库的话,那你就搜索一下php+mysql的入门教材。

发邮件与数据库无关,没有必要用到mysql,参考以下文章:

http://www.360doc.com/content/09/0313/21/71366_2800135.shtml

一般情况下比如你的邮箱是163.com的

那smtp服务器一般是:smtp.163.com
POP3一般是:pop3.163.com

不知道你是内部还是外部

mail($to, $subject, $message);

$to 你的邮箱
$subject 邮件主题
$message 正文内容,(就把表单 姓名,电话,邮箱,问题描述整合到这里面一起发)
=======
邮箱的SMTP和POP3
进到相应的邮箱,找到邮箱设置 然后就会有的了


麻烦各位高手大虾们 给小弟一个 php 简单的树形菜单 代码! 要注释...
;} treeStr = $treeStr."";}@mysql_free_result($rs);if ($TID == 0) { treeStr = $treeStr."";} return $treeStr;} ?> 3.页面上调用 <?=getCategoryTree(0,"N_type","edit.php","1=1")?> 4.数据结构 id title TID1(上一级ID)

高手推荐一个php的集成开发环境
AppServ 这个功能超级的多,而且安装的时候就提示你是否指定端口,就不会发生和iis冲突的事情了。而且他提供的快捷操作也超级的多

怎么自己做一个网站呢?
1、付费代劳建站法:付费找懂得建网站的人,帮你搭建一个网站,这是最省时间和精力的方法,只要花钱就能搞定的事情。2、代码建站法:你自己学会写代码后,自己给自己搭建一个网站,这是最耗时间和精力的方法,入门要一两年、精通要三五年,因为你需要先学会比如:html、css、js、php等难懂的代码,你...

求高手帮我写一个获取网页内容的php正则表达式
如果你要和之间的所有源码,用 preg_match 就可以,不用preg_match_all ,如果你要里面的所有的 标签中的内容,可以用preg_match_all \/\/提取所有代码 pattern = '\/(.+?)\/is';preg_match($pattern, $string, $match);\/\/$match[0] 即为和之间的所有源码 echo $match[0];\/\/然后再提取之间...

想从零开始学习PHP,但无从下手,请有经验的老师给个出路
找个网站,网上有很多这方面的学习网站(兄弟连,优才网),然后先按照教程,把基础的学了。先学html基础,css基础,javascript基础,然后学php基础,学习的过程中代码都自己敲,不要用太智能的IDE,我当时是用vim,写代码过程中,会出现BUG,不会调试就百度,慢慢积累经验,边做也就渐渐知道哪些不懂,...

php 中如何实现跳转到一个新的页面
php页面自动跳转的几种实现方法:1.meta标签 2.使用header函数 3.使用JavaScript 方法一:使用meta标签 meta标签是html不可或缺的标签之一,它负责提供文档的元信息,其参数主要有:① http-equiv: 与文档中数据相关的HTTP文件首部 ② content: 与命名HTTP首部相关的数据 ③ name: 文档描述 ④ url:...

求高手写个PHP正则表达式
<?php $str = ' ';\/\/[\\'"] 表示 单引号或双引号\/\/.*?表示匹配任意字符\/\/s使得.可以匹配任意字符,如果没加,要用[\\s\\S]替换.,[\\s\\S] \\s表示空格,\\S表示非空格,因此涵盖任意字符\/\/需要匹配多个,使用preg_match_all替代preg_matchpreg_match(...

求php高手写一段简单的代码
static $deepth=0;rs=mysql_query("select * from types where type_p_id='$pid'");if(mysql_num_rows($rs)<=0){ return ;}else{ deepth++;} while($row=mysql_fetch_array($rs)){ echo str_repeat(' ',$deepth*2).'|';echo '+'.$row['type_name'];echo "";list1($row['...

当你看一个php项目时候,从哪开始看起呢、有什么流程没有、高手指教下...
现在大部分的程序都是M-V-C的,先找到Controller层,然后再找到View层,基本上就可以确定网站结构了~对于项目的进行过程基本上可以如下进行:1、明确项目的需求--这需要客户或者项目负责人亲自讲解;2、讨论项目需求--与客户或者项目负责人一起坐下来好好的谈论细节和技术评估;3、分解项目需求,确认开发...

一个php登入界面我刚学,都搞了两天了,还不行,高手教教我吧
建议 你先用 print_r($_POST) 函数检查下 传递的数值,并且用die()终止程序 然后 在适当位置 print_r($row) 检查下并且用die()终止程序 这是你贴出来的php页面里检查的 在student.php 1.看有否使用 session_start()2.用print_r($_SESSION) 检查下session 的值 并且用die()终止程序 --- ...

冠县14777476159: 请问如何用php实现表单提交后以邮件的形式发到邮箱中. -
温政欣洫: 用mail函数或者fsockopen函数来发送邮件.手册里的例子你看看吧:<?php$to = 'nobody@example.com';$subject = 'the subject';$message = 'hello';$headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers);?>

冠县14777476159: PHP怎么把表单提交到本页 -
温政欣洫: PHP把表单提交到本页,这个的话,我们是通过<form action="提交的文件名">来实现的,还有一个传值的方式,post或者是get可以通过METHOD来实现的,这里我写一段代码: <html> <head></head> <body> <form action='文件名' method="post"> 姓名<input type='text' value=""> 密码<input type='text' value=""> email<input type='text' value=""> </form> </body> </html>

冠县14777476159: 怎样用php提交表单到发送邮件 -
温政欣洫: $mailbody =$_POST; 你把$_POST赋给了邮件内容,而$_POST本来就是一个数组 所以会显示是Array 改成:$mailbody =$_POST["name"]."\n".$_POST['add']."\n".$_POST['c']."\n".$_POST['d']; 试试看?

冠县14777476159: 点击提交按钮,php怎样把html表单里的内容发送到数据库?求代码,因为是新手,对这个不懂.谢谢 -
温政欣洫: 1.建数据库 2.建表单页 3.链接数据库,读取提交字段,插入语句插入数据库

冠县14777476159: php如何将表单数据提交给远程服务器 -
温政欣洫: 方式一:用GET方式直接把数据写在地址栏里 方式二:action里写上远程服务器地址,把表单数据写在hidden里POST给对方

冠县14777476159: php 初学者怎么实现表单的提交 -
温政欣洫: 给 form 表单添加 action 属性,属性值就是你接收表单数据的php页面地址,比如 html代码: <form action="1.php" ><input type="text" name="user"><input type="submit" value="提交" > </form>php代码: $user = $_GET['user']; echo $user;

冠县14777476159: php提交表单发送邮件 -
温政欣洫:require_once "email.class.php"; //******************** 配置信息 ******************************** $smtpserver = "smtp.126.com";//SMTP服务器 $smtpserverport =25;//SMTP服务器端口 $smtpusermail = "new2008oh@126.com";//SMTP服务器的...

冠县14777476159: 我网站用的是PHP. 需要如下功能.我从浏览器填写好一张表单然后提交,然后网站将我填好的表单发给 -
温政欣洫: 浏览器中表单样式可参考bootstrap,通过<form method="get" action=""><input .....></form>的方式,将表单内容提交并保存至数据表A中,A表中保存用户ID 以及其提交表单内容和提交给的另一个人的ID,当另一个人进入网站打开某链接,通过判断另一个人的用户ID,将A中数据展示在浏览器中,由这个人确认并提交,可将内容转存至另一个数据表B中,也可在A表中设置提交状态字段,若另一个人确认提交,直接更改其提交状态即可.

冠县14777476159: PHP如何实现向指定页面填写表单并提交?就是发贴
温政欣洫: 给你指定思路:先建立表单(表单使用POST方式提交)---- 在POST提交的方法里对表单进行获取值($title = $_REQUEST['title'])---- 再将获取到的值保存到数据库里就行了

冠县14777476159: php表单怎么提交在自己本页面啊? -
温政欣洫: 你在HTML里面嵌入php语法咯. $_GET或者$_POST <?php echo $_GET['a']; echo $_POST['a']; ?> 这样就可以了,在表单页面嵌入,里面的'a'改成你表单里面的name值

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网