php - Automatic email from form -
i'm creating database system user can add details within form , adds database php. want send confirmation email send of details within form. so, when add details of student instance email send me says along lines of "a student called "bob dabilda" has been added database "agentname"" - have no problem doing agent name part since can send session name through, have problems sending forward student name. appreciated. following version of add student php part. adding student form works , email works separately want email sent without agent having click button says "send email" or that. database mysql.
require "dbc.php"; session_start(); if(isset($_post['submit'])) { $sname = mysql_real_escape_string($_post['shostfamilyid']); if($sname && $ssurname && $sgender && $saddress && $sdob && $sblood && $spassport && $shobby1 && $shobby2 && $schildren && $sanimals) { $query = mysql_query("insert student values ('','$sname','$ssurname','$sgender','$saddress','$semail','$sdob','$stelephone','$sdiet','$sallergy','$smed','$sblood','$spassport','$shobby1','$shobby2','$shobby3','$ssiblings','$schildren','$srequests','$sanimals','$agent','')"); header("location: successstudent2.php"); } else { echo "check required fields completed"; } }
and copy of email script have working
session_start(); error_reporting(0); if($_session['username']) { $to = "from@from.com"; $from = "receive <to@to.com>"; $name = $_post['webmaster']; $email = $_post['email@email.com']; $msg = $_post['msg']; //generic subject $subject = "student adding"; //header $header = 'from: '. $from . "\r\n" . 'content-type: text/html; charset=iso-8859-1'; //email $htmlemail = " <html> <head> </head> <body> <font face='arial' style='font-size:14px;'></font><br> <font face='arial' style='font-size:14px;'>a student added ".$_session['username']." </font><br><br> </body> </html>"; //php mail function mail($to,$subject,$htmlemail,$header); header('location:members.php'); //forwards user members.php }
any appreciated. thanking you!
you need double check variable names , data being passed below, example , not functional as-is.
create function in common file, example (say "functions.php"):
<?php function send_email ($to, $from, $subject, $body) { /* you'll want modify above variables match need in function */ $to = "from@from.com"; $from = "receive <to@to.com>"; $name = $_post['webmaster']; $email = $_post['email@email.com']; $msg = $_post['msg']; //generic subject $subject = "student adding"; //header $header = 'from: '. $from . "\r\n" . 'content-type: text/html; charset=iso-8859-1'; //email $htmlemail = " <html> <head> </head> <body> <font face='arial' style='font-size:14px;'></font><br> <font face='arial' style='font-size:14px;'>a student added ".$_session['username']." </font><br><br> </body> </html>"; //php mail function mail($to, $subject, $htmlemail, $header); } ?>
then change code insert bit:
<?php session_start(); require "dbc.php"; require "functions.php"; if (isset($_post['submit'])) { $sname = mysql_real_escape_string($_post['shostfamilyid']); if ($sname && $ssurname && $sgender && $saddress && $sdob && $sblood && $spassport && $shobby1 && $shobby2 && $schildren && $sanimals) { $query = mysql_query("insert student values ('','$sname','$ssurname','$sgender','$saddress','$semail','$sdob','$stelephone','$sdiet','$sallergy','$smed','$sblood','$spassport','$shobby1','$shobby2','$shobby3','$ssiblings','$schildren','$srequests','$sanimals','$agent','')"); if ($query) { send_email ($to, $from, $subject, $body); /* modify these */ header("location: successstudent2.php"); exit(); } else { echo "check required fields completed"; } } } ?>
Comments
Post a Comment