943,604 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1223
  • PHP RSS
Aug 1st, 2008
0

Sending form data in an email

Expand Post »
Hi, guys. I've got a simple registration form that is submitting new user's contact information into a MySQL database. However, now when the form is submitted, I need the data to be sent in an email to the site's admin.

Anybody know a good resource for this?

Thanks!

Tom Tolleson
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Tom Tolleson is offline Offline
39 posts
since Oct 2007
Aug 1st, 2008
0

Re: Sending form data in an email

try this code:
PHP Syntax (Toggle Plain Text)
  1. //OPTIONS
  2. $sendTo = 'email@ofadmin.com'; //address to end form contants to
  3. $subject = 'Enter you subject here'; //subject of the e-mail
  4.  
  5. //mail headers
  6. $MAIL_HEADER = ("From: no-reply@yourdomain.com\n");
  7. $MAIL_HEADER .= ("Reply-To: no-reply@yourdomain.com\n");
  8. $MAIL_HEADER .= ("Content-Type: text/html; charset=us-ascii\n");
  9. $MAIL_HEADER .= ("MIME-Version: 1.0\n\n");
  10.  
  11. //setup message content
  12. $mailContent = 'Enter you data here'; //this is where you add your data to be sent as the message it can be formated in html if you wish
  13. //$mailContent .= 'second line of data'; ///you can add a line to the data here if you want
  14.  
  15. try { //try sending the e-mail
  16. mail( $sendTo, $subject, $mailContent, $MAIL_HEADER );
  17. //print('Thank you, your message has been sent.'); //if you want a message after email sent
  18. exit;
  19. } catch (Exception $e) { //send failed let's throw something
  20. echo 'Caught exception: ', $e->getMessage(), "\n";
  21. exit;
  22. }

hope this helps!
Last edited by jel3; Aug 1st, 2008 at 6:25 pm.
Reputation Points: 12
Solved Threads: 3
Newbie Poster
jel3 is offline Offline
18 posts
since May 2008
Aug 2nd, 2008
0

Re: Sending form data in an email

yes,put the above code after your insert query....
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Aug 2nd, 2008
0

Re: Sending form data in an email

This is assuming of course, you're guarding against SQL injections, before you send all this stuff...
Last edited by Demiloy; Aug 2nd, 2008 at 1:14 am.
Reputation Points: 12
Solved Threads: 6
Light Poster
Demiloy is offline Offline
48 posts
since Aug 2008
Aug 2nd, 2008
0

Re: Sending form data in an email

Hi, guys. I've got a simple registration form that is submitting new user's contact information into a MySQL database. However, now when the form is submitted, I need the data to be sent in an email to the site's admin.

Anybody know a good resource for this?

Thanks!

Tom Tolleson
PHP PAGE


PHP Syntax (Toggle Plain Text)
  1. <?
  2. $artwork =@addslashes($_POST['service']);
  3. $company=$_POST['company'];
  4. $city=$_POST['city'];
  5. $state=$_POST['state'];
  6. $country=$_POST['country'];
  7. $name=$_POST['name'];
  8. $email=$_POST['email'];
  9. $phone=$_POST['phone'];
  10. $domain=$_POST['domain'];
  11. $existing=$_POST['existing'];
  12. $others=$_POST['others'];
  13. $search=$_POST['search1'];
  14.  
  15. $artwork=(!empty($_POST['service'])? array_map('stripslashes',$_POST['service']) : '');
  16. echo $mail_body='<style type=text/css><!--td {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;}--></style>
  17. <table width="50%" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#E7E7E7">
  18. <tr>
  19. <td><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
  20. <input type="hidden" name="contact" value="ok">
  21. <tr>
  22. <td colspan="3" align="center" height=35><strong>Contact Details</strong></td>
  23. </tr>
  24. <tr>
  25. <td width="34%">Company</td>
  26. <td width="3%">:</td>
  27. <td width="63%">'.$company.'</td>
  28. </tr><tr>
  29. <td width="34%">City</td>
  30. <td width="3%">:</td>
  31. <td width="63%">'.$city.'</td>
  32. </tr>
  33. <tr>
  34. <td width="34%">state</td>
  35. <td width="3%">:</td>
  36. <td width="63%">'.$state.'</td>
  37. </tr>
  38. <tr>
  39. <td width="34%">Country</td>
  40. <td width="3%">:</td>
  41. <td width="63%">'.$country.'</td>
  42. </tr>
  43. <tr>
  44. <td width="34%">Name</td>
  45. <td width="3%">:</td>
  46. <td width="63%">'.$name.'</td>
  47. </tr>
  48. <tr>
  49. <td>email </td>
  50. <td>:</td>
  51. <td>'.$email.'</td>
  52. </tr>
  53. <tr>
  54. <td>phone </td>
  55. <td>:</td>
  56. <td>'.$phone.'</td>
  57. </tr>
  58. <tr>
  59. <td>Domain </td>
  60. <td>:</td>
  61. <td>'.$domain.'</td>
  62. </tr>
  63. <tr>
  64. <td>Existing </td>
  65. <td>:</td>
  66. <td>'.$existing.'</td>
  67. </tr>
  68. <tr>
  69. <td>Services </td>
  70. <td>:</td>
  71. <td>
  72.  
  73. '.(is_array($artwork)? implode(",",$artwork) : '').'
  74.  
  75.  
  76. </td>
  77. </tr>
  78.  
  79.  
  80. <tr>
  81. <td>Other Requirements </td>
  82. <td>:</td>
  83. <td>'.$others.'</td>
  84. </tr>
  85. <tr>
  86. <td>Search Engine </td>
  87. <td>:</td>
  88. <td>'.$search.'</td>
  89. </tr>
  90. <tr>
  91. <td>&nbsp;</td>
  92. <td>&nbsp;</td>
  93. <td>&nbsp;</td>
  94. </tr>
  95. </table></td>
  96. </tr>
  97. </table>';
  98. exit;
  99.  
  100. //echo $mail_body;exit;
  101. $mailto = 'yourmailid' ;
  102.  
  103. $mailheader = 'MIME-Version: 1.0' . "\r\n";
  104. $mailheader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  105. $mailheader.=" From: ".$_POST['email']."\r\n";
  106. //$mailheader .= 'BCc: 'ex@ex.com' '. "\r\n";
  107. @mail($mailto,'Contact Us Details',$mail_body,$mailheader);
  108. echo '<script language="javascript">window.location.href="thanku.html";</script>';
  109.  
  110.  
  111. ?>

PHP Syntax (Toggle Plain Text)
  1. <HTML>
  2. <HEAD>
  3. <title></title>
  4.  
  5. <meta name="keywords" content="">
  6.  
  7.  
  8.  
  9.  
  10.  
  11. <script language="JavaScript" type="text/JavaScript" src="website_design_javascript.js"></script>
  12. <link href="website_development_stylesheet.css" rel="stylesheet" type="text/css">
  13. <style type="text/css">
  14. <!--
  15. .noborder{font-size:18px;font-family:Verdana, Arial, Helvetica, sans-serif;border-bottom: #ffffff 0px solid;border-top: #ffffff 1px solid;border-left: #ffffff 1px solid;border-right: #ffffff 0px solid;COLOR: #000000}
  16. .style21 {font-family: Verdana, Arial, Helvetica, sans-serif}
  17. .style25 {font-size: 12px}
  18. .style27 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
  19. .style28 {color: #000000}
  20. .style29 {font-family: Verdana, Arial, Helvetica, sans-serif; color: #000000;}
  21. .style30 {color: #FF0000}
  22. -->
  23. </style>
  24. </HEAD>
  25. <BODY LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 onLoad="MM_preloadImages('../images/mid-links-over_02.gif','../images/mid-links-over_03.gif','../images/mid-links-over_04.gif','../images/mid-links-over_05.gif')">
  26. <TABLE WIDTH=775 BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0>
  27. <TR>
  28.  
  29. <TD width="760" align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  30.  
  31. <tr>
  32. <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  33. <tr>
  34.  
  35. <td width="577" align="left" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
  36.  
  37. <tr>
  38.  
  39. <tr>
  40. <td align="left" valign="top">
  41. <SCRIPT>//global variable for error flag
  42. var errfound = false;
  43. //function to validate by length
  44. function ValidLength(item, len) {
  45. return (item.length >= len);
  46. }
  47. //function to validate an email address
  48. function ValidEmail(item) {
  49. if (!ValidLength(item, 5)) return false;
  50. if (item.indexOf ('@', 0) == -1) return false;
  51.  
  52. return true;
  53. }
  54. // display an error alert
  55. function error(elem, text) {
  56. // abort if we already found an error
  57. if (errfound) return;
  58. window.alert(text);
  59. elem.select();
  60. elem.focus();
  61. errfound = true;
  62. }
  63. // main validation function
  64. function Validate() {
  65. errfound = false;
  66. if (!ValidLength(document.form.company.value,1))
  67. error(document.form.company,"Enter Your Company Name");
  68. if (!ValidLength(document.form.city.value,1))
  69. error(document.form.city,"Enter Your City Name");
  70. if (!ValidLength(document.form.state.value,1))
  71. error(document.form.state, "Enter Your State Name");
  72. if (!ValidLength(document.form.country.value,1))
  73. error(document.form.country, "Enter Your Country Name");
  74. if (!ValidLength(document.form.name.value,1))
  75. error(document.form.name, "Enter Your Name");
  76.  
  77. if (!ValidEmail(document.form.email.value,1))
  78. error(document.form.email,"Enter Your Email Id");
  79. if (!ValidLength(document.form.phone.value,1))
  80. error(document.form.phone,"Enter Your Phone Number");
  81.  
  82. if (!ValidLength(document.form.search1.value,1))
  83. error(document.form.search1,"Enter Search engine Name");
  84.  
  85. return !errfound; /* true if there are no errors */
  86. }</SCRIPT> <SCRIPT language="javascript">
  87. function Only_Num(id) {
  88. if(isNaN(document.getElementById(id).value)) {
  89. alert("Please Enter Numbers Only (0-9)..");
  90. document.getElementById(id).select();
  91. document.getElementById(id).value=""
  92. document.getElementById(id).focus();
  93. }
  94. return;
  95. }
  96. </SCRIPT> <form name="form" action="requsetsubmit.php" method="post">
  97. <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  98. <tr>
  99. <td><table width="100%" border="0" cellspacing="0" cellpadding="5">
  100. <tr>
  101. <td width="33%" class="style10 style21 style25">Company Name <font color="#FF0000">*</font></td>
  102. <td width="3%" class="style10 style21 style25">:</td>
  103. <td width="64%"><input name="company" type="text" class="style29" id="company" size="25" maxlength="75"></td>
  104. </tr>
  105. <tr>
  106. <td class="style10 style21 style25">City<font color="#FF0000">*</font></td>
  107. <td class="style10 style21 style25">:</td>
  108. <td><input name="city" type="text" id="city" size="20" maxlength="50"></td>
  109. </tr>
  110. <tr>
  111. <td class="style10 style21 style25">State / Province<font color="#FF0000">*</font> </td>
  112. <td class="style10 style21 style25">:</td>
  113. <td><input name="state" type="text" id="state" size="20" maxlength="50"></td>
  114. </tr>
  115. <tr>
  116. <td class="style10 style21 style25">Country <font color="#FF0000">*</font></td>
  117. <td class="style10 style21 style25">:</td>
  118. <td><input name="country" type="text" id="country" size="15" maxlength="50"></td>
  119. </tr>
  120. <tr>
  121. <td class="style10 style21 style25">Your Name <font color="#FF0000">*</font></td>
  122. <td class="style10 style21 style25">:</td>
  123. <td><input name="name" type="text" id="name" size="25" maxlength="75"></td>
  124. </tr>
  125. <tr>
  126. <td class="style10 style21 style25">E-Mail <font color="#FF0000">*</font></td>
  127. <td class="style10 style21 style25">:</td>
  128. <td><input name="email" type="text" id="email" size="30" maxlength="75"></td>
  129. </tr>
  130. <tr>
  131. <td class="style10 style21 style25">Phone<font color="#FF0000">*</font></td>
  132. <td class="style10 style21 style25">:</td>
  133. <td><input name="phone" type="text" id="phone" size="15" maxlength="50"onChange="Javascript:LA()" onKeyUp="Only_Num(this.id)"></td>
  134. </tr>
  135. <tr>
  136. <td class="style10 style21 style25">Domain Name Required ...?</td>
  137. <td class="style10 style21 style25">:</td>
  138. <td><span class="style27">
  139. <input name="radiobutton" type="radio" class="style7" value="Yes" checked>
  140. <span class="style28">Yes</span></span>
  141. <span class="style27">
  142. <input name="radiobutton" type="radio" class="style7" value="No">
  143. <span class="style28">No</span></span></td>
  144. </tr>
  145. <tr>
  146. <td class="style10 style21 style25">if Yes provide Domain Name</td>
  147. <td class="style10 style21 style25">:</td>
  148. <td><input name="domain" type="text" id="domain" size="30" maxlength="100"></td>
  149. </tr>
  150. <tr>
  151. <td class="style10 style21 style25">If No Give us Existing Web Site Name </td>
  152. <td class="style10 style21 style25">:</td>
  153. <td><input name="existing" type="text" id="existing" size="30" maxlength="100"></td>
  154. </tr>
  155. <tr>
  156. <td class="style10 style21 style25">Looking for the following Services</td>
  157. <td class="style10 style21 style25">:</td>
  158. <td><span class="style27">
  159. <input name="service[]" type="checkbox" class="style7" value="Design New Site">
  160. Design New Site<br>
  161. <input name="service[]" type="checkbox" class="style7" value="Re-Design Existing Site">
  162. Re-Design Existing Site<br>
  163. <input name="service[]" type="checkbox" class="style7" value="Search Engine Registration">
  164. Search Engine Registration<br>
  165. <input name="service[]" type="checkbox" class="style7" value="Payment Gateway Solutions">
  166. Payment Gateway Solutions</span></td>
  167. </tr>
  168. <tr>
  169. <td class="style10 style21 style25">Are you Looking for Hosting Space</td>
  170. <td class="style10 style21 style25">:</td>
  171. <td><span class="style27">
  172. <input name="radiobutton1" type="radio" class="style7" value="Yes" checked>
  173. Yes</span>
  174. <span class="style27">
  175. <input name="radiobutton1" type="radio" class="style7" value="No">
  176. No</span></td>
  177. </tr>
  178. <tr>
  179. <td class="style10 style21 style25">Other Requirements</td>
  180. <td class="style10 style21 style25">:</td>
  181. <td><textarea name="others" cols="30" rows="4" wrap="VIRTUAL" class="style7 style21 style25" id="others"></textarea></td>
  182. </tr>
  183. <tr>
  184. <td class="style10 style21 style25">In which Search Engine you found us..? <font color="#FF0000">*</font></td>
  185. <td class="style10 style21 style25">:</td>
  186. <td><span class="style27">
  187. <input name="search1" type="text" class="style7" id="search" size="20" maxlength="100">
  188. (Ex:Google,Yahoo..etc)</span></td>
  189. </tr>
  190. <tr>
  191. <td class="style10 style21 style25">Which keyword you searched for..?</td>
  192. <td class="style10 style21 style25">:</td>
  193. <td><input name="keyword" type="text" id="keyword" size="35" maxlength="100"> </td>
  194. </tr>
  195. <tr align="center">
  196. <td colspan="3"><br>
  197. <input name="Submit" type="submit" class="style7" onClick="return Validate()" value="Submit">
  198. &nbsp;&nbsp;&nbsp;
  199. <input name="Submit2" type="reset" class="style7" value="Reset"></td>
  200. </tr>
  201. </table></td>
  202. </tr>
  203. </table>
  204. </form></td>
  205. </tr>
  206. </table></td>
  207. </tr>
  208. </table></td>
  209. </tr>
  210. </table></td>
  211. </tr>
  212.  
  213. </table></TD>
  214. <TD background="../images/back_03.gif"><IMG SRC="../images/back_03.gif" WIDTH=2 HEIGHT=45 ALT=""></TD>
  215. </TR>
  216. </TABLE>
  217. <script language="javascript">
  218. var randomnumber=Math.floor(Math.random()*99999);
  219. document.form1.rndnumber.value='9BNPL'+randomnumber
  220. </script>
  221. </BODY>
  222. </HTML>



Hi frnd.... i dont know how it is useful to u..
it is also registration for based on our requirement...than just u have to do some changes what ur requirement.....
Reputation Points: 10
Solved Threads: 7
Unverified User
saikishore is offline Offline
41 posts
since Jul 2008
Aug 14th, 2008
0

Re: Sending form data in an email

That's a really big help! Thanks guys, it works great!
Reputation Points: 10
Solved Threads: 0
Light Poster
Tom Tolleson is offline Offline
39 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: regular expression patterns
Next Thread in PHP Forum Timeline: images thumbnails view php script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC