PHP E-mail setting ???

Reply

Join Date: Jan 2006
Posts: 89
Reputation: j4mes_bond25 is an unknown quantity at this point 
Solved Threads: 0
j4mes_bond25's Avatar
j4mes_bond25 j4mes_bond25 is offline Offline
Junior Poster in Training

PHP E-mail setting ???

 
0
  #1
May 29th, 2006
After bending over backwards, I managed to finally get my form validation done, which seems working perfectly well.

After failing to work with e-mail, I wonder if anyone around could help me little towards e-mail so that as soon as someone presses "Submit" button, I get the entire form's message sent to me through an e-mail.

I've typed the e-mail related code right at the bottom of the form, although, I disabled the code so at least you can see the form since right now, it's showing some error message with the use of curly bracket ({).

I guess this e-mail related code should go somewhere up around the comment:
"// If there's NO error at all, along with displaying the filled fields"

I've typed in the comment all over the form, so as to make it easier to read & understand & knowing what's happening where.

I wish to receive the comment submitted on "j4mes_bond25@yahoo.co.uk".

Following is my "contact.php" code:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Personal Website</title>
  6. <link rel="stylesheet" type="text/css" href="style.css"/>
  7. </head>
  8.  
  9. <body>
  10. <?php // include("menu.inc");?>
  11.  
  12. <div id="centerContent">
  13.  
  14. <p>
  15.  
  16. <?php
  17.  
  18. // If the form has been posted, analyse it:
  19. if ($_POST) {
  20. foreach ($_POST as $field => $value) {
  21. $value = trim($value);
  22. }
  23.  
  24. // Creating Variables
  25. $inquiry=$_POST['inquiry'];
  26. $title=$_POST['title'];
  27. $first_name=$_POST['first_name'];
  28. $last_name=$_POST['last_name'];
  29. $email=$_POST['email'];
  30. $phone=$_POST['phone'];
  31. $message=$_POST['message'];
  32. $reply=$_POST['reply'];
  33. $contact=$_POST['contact'];
  34.  
  35. // Create empty ERROR variables
  36. $error = ""; // for fields left BLANK
  37. $errorflag = ""; // for fields with INVALID data entered
  38.  
  39. // Check for field/fields that is/are left BLANK
  40. if (($first_name == "") || ($last_name == "") || ($email == "") || ($phone == "") || ($message == "")) {
  41. $error = "Please fill in all fields!";
  42. }
  43. else {
  44. // Validate First Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
  45. if (ctype_alpha($first_name) == FALSE) {
  46. $error = "Please enter a valid name <span class='italic'>(Alphabets only)</span>";
  47. $errorflag= "first_name";
  48. }
  49. // Validate Last Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
  50. else if (ctype_alpha($last_name) == FALSE) {
  51. $error = "Please enter a valid last name <span class='italic'>(Alphabets only)</span>";
  52. $errorflag="last_name";
  53. }
  54. // Validate E-mail (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
  55. else if ((strpos($email, "@") == FALSE)||
  56. (strpos($email, ".") == FALSE) ||
  57. (strpos($email, " ") != FALSE)) {
  58. $error = "Please enter a valid e-mail address";
  59. $errorflag="email";
  60. }
  61. // Validate Contact No. (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
  62. else if (is_numeric($phone) == FALSE) {
  63. $error = "Please enter a valid contact number <span class='italic'>(must contain numbers only)</span>";
  64. $errorflag="phone";
  65. }
  66. }
  67. // Confirmation Message seen AFTER filling the form and pressing "Submit" button (whether there's an error or not)
  68. if ($error != "") { echo "<b><span class='colorText'>Error Occured: </b>" . $error."</span>" ; } // If there's an error along with displaying the list of flagged error/errors
  69.  
  70. // If there's NO error at all, along with displaying the filled fields
  71. else { echo "<p>Thanks for your comment and time. We will be in touch with you shortly.<br/><br/>";
  72. echo "<b>Nature of Inquiry:</b> ". $inquiry . "<br/>";
  73. echo "<b>Title:</b> ". $title . "<br/>";
  74. echo "<b>First Name:</b> ". $first_name . "<br/>";
  75. echo "<b>Last Name:</b> ". $last_name . "<br/>";
  76. echo "<b>E-mail:</b> ". $email . "<br/>";
  77. echo "<b>Contact No.:</b> ". $phone . "<br/>";
  78. echo "<b>Message:</b> ". $message . "<br/>";
  79. echo "<b>Reply:</b> ". $reply . "<br/>";
  80. echo "<b>Contact Method:</b> ". $contact . "<br/></p>";
  81. }
  82. }
  83. // DON'T KNOW WHY THERE'S "ELSE" CODE HERE
  84. else {
  85.  
  86. $inquiry = "";
  87. $title = "";
  88. $first_name = "";
  89. $last_name = "";
  90. $email = "";
  91. $phone = "";
  92. $message = "";
  93. $reply = "";
  94. $contact = "";
  95. $errorflag = "";
  96. }
  97.  
  98. ?>
  99. </p>
  100.  
  101. <p class="first-letter">Please fill the following form in for any enquiries that you may have:</p>
  102.  
  103. <table id="contactTable">
  104.  
  105. <tr id="contactTr">
  106. <td id="contactTd"><form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  107. Nature of Enquiry:</td>
  108. <td id="contactTd"><select name="inquiry">
  109. <option <?php if ($inquiry == "General Inquiry") echo "Selected"; ?> value = "General Inquiry">General Inquiry</option>
  110. <option <?php if ($inquiry == "Price Quotation") echo "Selected"; ?> value = "Price Quotation">Price Quotation</option>
  111. <option <?php if ($inquiry == "Comments") echo "Selected"; ?> value = "Comments">Comments</option>
  112. <option <?php if ($inquiry == "Other") echo "Selected"; ?> value = "Other">Other</option>
  113. </select></td>
  114. </tr>
  115.  
  116. <tr id="contactTr">
  117. <td id="contactTd">Title:</td>
  118. <td id="contactTd"><select name="title"/>
  119. <option <?php if ($title == "Mr") echo "Selected"; ?> value = "Mr">Mr</option>
  120. <option <?php if ($title == "Miss") echo "Selected"; ?> value = "Miss">Miss</option>
  121. <option <?php if ($title == "Ms") echo "Selected"; ?> value = "Ms">Ms</option>
  122. <option <?php if ($title == "Mrs") echo "Selected"; ?> value = "Mrs">Mrs</option>
  123. <option <?php if ($title == "Other") echo "Selected"; ?> value = "Other">Other</option>
  124. </select></td>
  125. </tr>
  126.  
  127. <tr id="contactTr">
  128. <td id="contactTd"><?php if ($errorflag == "first_name") { echo "<span class='colorText'>First Name:</span>"; }
  129. else { echo "First Name:"; } ?></td>
  130. <td id="contactTd"><input type="text" size="30" maxlength="30" name="first_name" value="<?php echo $first_name; ?>"/></td>
  131. </tr>
  132.  
  133. <tr id="contactTr">
  134. <td id="contactTd"><?php if ($errorflag == "last_name") { echo "<span class='colorText'>Last Name:</span>"; }
  135. else { echo "Last name:"; } ?></td>
  136. <td id="contactTd"><input type="text" size="30" maxlength="30" name="last_name" value="<?php echo $last_name; ?>"/></td>
  137. </tr>
  138.  
  139. <tr id="contactTr">
  140. <td id="contactTd"><?php if ($errorflag == "email") { echo "<span class='colorText'>E-mail:</span>"; }
  141. else { echo "E-mail:"; } ?></td>
  142. <td id="contactTd"><input type="text" size="30" maxlength="30" name="email" value="<?php echo $email; ?>"/></td>
  143. </tr>
  144.  
  145. <tr id="contactTr">
  146. <td id="contactTd"><?php if ($errorflag == "phone") { echo "<span class='colorText'>Contact No.:</span>"; }
  147. else { echo "Contact No.:"; } ?></td>
  148. <td id="contactTd"><input type="text" size="30" maxlength="20" name="phone" value="<?php echo $phone; ?>"/></td>
  149. </tr>
  150.  
  151. <tr id="contactTr">
  152. <td id="contactTd">Message:</td>
  153. <td id="contactTd"><textarea rows="10" cols="50" wrap="physical" name="message"/><?php echo $message; ?>
  154. </textarea></td>
  155. </tr>
  156.  
  157. <tr id="contactTr">
  158. <td id="contactTd">Reply Required:</td>
  159. <td id="contactTd"><input type="radio" name="reply" value="Yes" checked="checked"/>Yes
  160. <input type="radio" name="reply" value="No" <?php if ($reply="No") echo "checked='checked'"; ?>/>No</td>
  161. </tr>
  162.  
  163. <tr id="contactTr">
  164. <td id="contactTd">How would you like to be contacted (if required)?<br/><br/></td>
  165. <td id="contactTd"><input type="radio" name="contact" value="Email" checked="checked"/>E-mail
  166. <input type="radio" name="contact" value="Telephone" <?php if ($contact="Telephone") echo "checked='checked'"; ?>/>Telephone
  167. </td>
  168. </tr>
  169.  
  170. <tr id="contactTr">
  171. <td id="contactTd"></td>
  172. <td id="contactTd"><input type="reset" name="reset" value="Reset">
  173. <input type="submit" name="submit" value="Submit"></td>
  174. </form>
  175. </tr>
  176. </table>
  177.  
  178. <?php
  179. /*
  180. if ($_POST) {
  181. if (mail("j4mes_bond25@yahoo.co.uk", $_POST['inquiry'], stripslashes($_POST['message'], "From: " .$_POST['email']."r\n")) {
  182. echo "E-mail sent successfully";
  183. }
  184. elseif {
  185. echo "E-mail NOT sent";
  186. }
  187. }
  188. */
  189. ?>
  190.  
  191. </div>
  192. </body>
  193. </html>
Nope, I'm NOT God, but I'm British (which is the next best thing ;)
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 32
Reputation: BlazingWolf is an unknown quantity at this point 
Solved Threads: 1
BlazingWolf BlazingWolf is offline Offline
Light Poster

Re: PHP E-mail setting ???

 
0
  #2
May 29th, 2006
You have to set what SMTP(Outgoing) Mail server you are going to user first. In order to set that use.

[php]ini_set(smtp, "mail.myserver.net");
ini_set(smtp_port, 25); //25 is the default leave it at that if you are unsure.
[/php]
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 89
Reputation: j4mes_bond25 is an unknown quantity at this point 
Solved Threads: 0
j4mes_bond25's Avatar
j4mes_bond25 j4mes_bond25 is offline Offline
Junior Poster in Training

Re: PHP E-mail setting ???

 
0
  #3
May 30th, 2006
Originally Posted by BlazingWolf
You have to set what SMTP(Outgoing) Mail server you are going to user first. In order to set that use.

[php]ini_set(smtp, "mail.myserver.net");
ini_set(smtp_port, 25); //25 is the default leave it at that if you are unsure.
[/php]
Do I set this SMTP Mail server in different file (if so, would it have ".php" extention ???) or do I simply type this code within the same file "contact.php".

By the way, may not be a rather sensible question but, instead of "myserver", do I change it to "apache" since that is the server I'm using for PHP OR do I leave it as "mail.myserver.net", as it's now.
Nope, I'm NOT God, but I'm British (which is the next best thing ;)
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 32
Reputation: BlazingWolf is an unknown quantity at this point 
Solved Threads: 1
BlazingWolf BlazingWolf is offline Offline
Light Poster

Re: PHP E-mail setting ???

 
0
  #4
May 30th, 2006
You want to leave those to lines in whatever files you are sending the mail in.

The mail.myserver.net is whatever your SMTP mail server is for instance mine is smtp.charter.net because charter is my hosting provider. If you use a email client like Outlook or Thunderbird you will have had to use this outgoing mail server address, so you can look it up in your settings.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC