473,503 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How anyone can send email to members with a form?

2 New Member
Hello everyone,

I'm new to PHP and creating an advertising website for massage therapists. On the profile page I'm creating a button so anyone can click on to send the advertiser an email.

I created a page called profile_sendemail.php which contains the form to send the email and here is the code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Start_session, check if user is logged in or not, and connect to the database all in one included file
  3. include_once("scripts/checkuserlog.php");
  4. // Include the class files for auto making links out of full URLs and for Time Ago date formatting
  5. include_once("wi_class_files/autoMakeLinks.php");
  6. include_once ("wi_class_files/agoTimeFormat.php");
  7. // Create the two new objects before we can use them below in this script
  8. $activeLinkObject = new autoActiveLink;
  9. $myObject = new convertToAgo;
  10. ?>
  11.  
  12. <?php
  13. // Now let's initialize vars to be printed to page in the HTML section so our script does not return errors
  14. // they must be initialized in some server environments
  15. $id = "";
  16. $firstname = "";
  17. $middlename = "";
  18. $lastname = "";
  19. $email = "";
  20.  
  21. // If coming from category page
  22. if ($_GET['id']) {
  23.  
  24. $id = $_GET['id'];
  25.  
  26. } else if (isset($_SESSION['id'])) {
  27.  
  28. $id = $_SESSION['id'];
  29.  
  30. } else {
  31.  
  32. $id = $_SESSION['id'];
  33.  
  34. include_once "index.php";
  35. exit();
  36. }
  37. $id = mysql_real_escape_string($id);
  38. $id = eregi_replace("`", "", $id);
  39. $sql = mysql_query("SELECT * FROM myMembers WHERE id='$id'");
  40.  
  41. while($row = mysql_fetch_array($sql)){
  42.  
  43. $id = $row["id"];
  44. $firstname = $row["firstname"];
  45. $lastname = $row["lastname"];
  46.  
  47.  
  48. } // close while loop
  49.  
  50. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. $style_sheet = "default";
  52. ?>
  53.  
  54.  
  55. <?php
  56. ////////////////////////// MECHANISM TO SEND EMAILS ////////////////////////////////////////////////
  57.  
  58.  
  59. if(isset($_POST['email'])) {
  60.  
  61. // EDIT THE 2 LINES BELOW AS REQUIRED
  62. $email_to = "$email";
  63. $email_subject = "New appointment request on MassageTherapistsList.com";
  64.  
  65.  
  66. function died($error) {
  67. // your error code can go here
  68. echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  69. echo "These errors appear below.<br /><br />";
  70. echo $error."<br /><br />";
  71. echo "Please go back and fix these errors.<br /><br />";
  72. die();
  73. }
  74.  
  75. // validation expected data exists
  76. if(!isset($_POST['name']) ||
  77. !isset($_POST['email']) ||
  78. !isset($_POST['comments'])) {
  79. died('We are sorry, but there appears to be a problem with the form you submitted.');
  80. }
  81.  
  82. $name = $_POST['name']; // required
  83. $email_from = $_POST['email']; // required
  84. $comments = $_POST['comments']; // required
  85.  
  86. $error_message = "";
  87. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  88. if(!preg_match($email_exp,$email_from)) {
  89. $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  90. }
  91. $string_exp = "/^[A-Za-z .'-]+$/";
  92. if(!preg_match($string_exp,$name)) {
  93. $error_message .= 'The Name you entered does not appear to be valid.<br />';
  94. }
  95. if(strlen($comments) < 2) {
  96. $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  97. }
  98. if(strlen($error_message) > 0) {
  99. died($error_message);
  100. }
  101. $email_message = "Form details below.\n\n";
  102.  
  103. function clean_string($string) {
  104. $bad = array("content-type","bcc:","to:","cc:","href");
  105. return str_replace($bad,"",$string);
  106. }
  107.  
  108. $email_message .= "Name: ".clean_string($name)."\n";
  109. $email_message .= "Email: ".clean_string($email_from)."\n";
  110. $email_message .= "Comments: ".clean_string($comments)."\n";
  111.  
  112.  
  113. // create email headers
  114. $headers = 'From: '.$email_from."\r\n".
  115. 'Reply-To: '.$email_from."\r\n" .
  116. 'X-Mailer: PHP/' . phpversion();
  117. @mail($email_to, $email_subject, $email_message, $headers);
  118. ?>
  119.  
  120. <!-- include your own success html here -->
  121.  
  122. Thank you for contacting us. We will be in touch with you very soon.
  123.  
  124. <?php
  125.  
And the profile.php page I added the link with the following PHP function:

Expand|Select|Wrap|Line Numbers
  1. if (empty($_SESSION['id'])) {
  2. $_SESSION['id'] = $id;
  3. } else {
  4. $_SESSION['id']++;
  5. }
  6. ?>
  7.  
  8. <a href="profile_sendmail.php?id=".$id."<?php echo htmlspecialchars(SID); ?>">Send Email</a>
  9.  
However, when I click on "Send Email" I get the following url without id:

http://domain.com/profile_sendmail.php?id=

And of course a page Not Found error instead of the email form.

Any ideas what would be the best way to get the results I want?
Nov 3 '11 #1
0 1722

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1711
by: TIML | last post by:
The first page you come to in my Web application is default.asp. This gives the user the ability to click on a drop down menu and choose a prior date ( to update or add info) or they may simply...
1
2282
by: Bruce W.1 | last post by:
I'm new to ASP (but not ASP.NET) and I'm trying to setup a simple ASP web form to send an email to me. So I try this code: http://www.library.unr.edu/subjects/guides/mailplay.asp I upload the...
1
4455
by: mhawkins19 | last post by:
I have a form built and on the onclick event I validate all of the fields and then if the form is ok, on the submit event I run a javascript function to set a cookie and download a file from the...
9
4292
by: Bob Jones | last post by:
We have developed a commercial ASP.net application (personal nutrition management and tracking); we want to send smtp email from within it. For our development box, we use WinXP Pro, IIS 5.5,...
1
1500
by: PraveenKadkol | last post by:
Hi, My question : If my process is taking more than 30 mins to complete, then i need to send out email to all the users. I have two forms, 1 is "Main form" and another is dummy form, dummy...
7
3338
Atran
by: Atran | last post by:
Hello, I use Html 4.0 in Dreamweaver program, to send an email, I know that I must put a Form, and I make the Form Action: mailto:MyEmail@hotmail.com Then I put to the Form three textboxes:...
5
2343
by: canajien | last post by:
I have a form that stores information in a table, but I also need it to send an email when a specific question, among the many, is answered with no the question is a simple drop box: <select...
14
8336
by: Warren Tang | last post by:
Hi I am using the mail function to send a mail like this: $b = mail("my_real_email_address@gmail.com", "Hello from PHP", "Hi, finally sent an email successfully"); But it failed. Could you...
2
2876
by: PrabodhanP | last post by:
I want to send form data to email using ASP (post method). I am trying following script but it's not working.Please suggest. Also suggest how to redirect it after pressing submit button. <% Dim...
4
2000
by: dfluker | last post by:
This form will not send the email to my account and I used other forms to submit emails using examples that I googled but I can't get this form to process the request. Can someone tell me what i'm...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.