473,498 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP Form Mailer Problems

5 New Member
Hey guys,

I'm pretty new here and I need some help. What I want to do is very easy. I have a webpage (<Link removed>) that has a form on it and I want the information that is submitted on the form to be sent to my email and I want the user that clicked submit to be taken to a thankyou page (<Link removed>)

I have the form already created I just need you guys to double check these two certain parts of it. (the whole form is located on <Link removed>)
Expand|Select|Wrap|Line Numbers
  1. <form action="feedback.php" method="post">
  2.  
  3. <input value="Submit" name="B1" type="submit">
  4.  
Here is the feedback.php file that I am using that apparantly has some flaws in it. (Sorry it is kinda squished)
Expand|Select|Wrap|Line Numbers
  1. <?
  2. ///////////////////////////////////////////////////////////////////
  3. // PERFECT                                                       //
  4. // -------                                                       //
  5. // PHP E-mail Receive Form Electronic Content Text               //
  6. // File: feedback.php                                            //
  7. // Version: 1.6 (April 2, 2005)                                  //
  8. // Description: Processes a web form to read the user input and  //
  9. //    then send the data to a predefined recipient.  You are     //
  10. //    free to use and modify this script as you like.            //
  11. // Instructions:  Go to "<Link removed>".          //
  12. //                                                               //
  13. // Center Key Software  *  <Link removed>  *  Dem Pilafian    //
  14. ///////////////////////////////////////////////////////////////////
  15.  
  16. // Configuration Settings
  17. $SendFrom =    "Michael Alexander <<Email removed>>";
  18. $SendTo =      "<Email removed>";
  19. $SubjectLine = "Feedback Submission";
  20. $ThanksURL =   "<Link removed>";  //confirmation page
  21. $Divider =     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
  22.  
  23. // Build Message Body from Web Form Input
  24. $MsgBody = @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n$Divider\n";
  25. foreach ($_POST as $Field=>$Value)
  26.    $MsgBody .= "$Field: $Value\n";
  27. $MsgBody .= "$Divider\n" . $_SERVER["HTTP_USER_AGENT"] . "\n";
  28. $MsgBody = htmlspecialchars($MsgBody);  //make content safe
  29.  
  30. // Send E-Mail and Direct Browser to Confirmation Page
  31. mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom");
  32. header("Location: <Link removed>");
  33. ?>
  34.  
I'm sure it is a quick and easy fix and that I'll be embarrased when it's all said and done with but thanks in advance for the help.
Oct 3 '07 #1
10 2028
Atli
5,058 Recognized Expert Expert
Hi Michael. Welcome to The Scripts!

I'm not sure what the problem with your code is?
Could you explain exactly what is wrong in your code?
Are you getting any errors?

P.S.
I have removed several links and emails from your post.

Posting links to a site that is in competition with TSDN, that contains advertisement or any other inappropriate content is a violation of the Postin Guidelines, specifically the part about Things that are generally unacceptable.

We do not allow posting of emails (yours or others) in the public forums. This is mainly for your security, as it will most likely be picked up by spammers if you leave it laying around a public forum.

Lastly, please enclose your posted code in [code] tags (See How to Ask a Question).

Moderator
Oct 3 '07 #2
Michael117
5 New Member
Hey Atli,

Thanks for the quick reply and for editing my post, I should have been more careful when posting.
Alright so basically my problem is that whenever I fill out the information for the form on my webpage and click submit it doesn’t do anything, it doesn’t even send me to an error 404 page or anything. It doesn't send me an email with the form information or send you to the thankyou page.
What I think I did wrong was filling in the field values for the php file
(ex: $SendFrom). Here is the code for the php file.
Expand|Select|Wrap|Line Numbers
  1. 1.    <?
  2. 2.    ///////////////////////////////////////////////////////////////////
  3. 3.    // PERFECT                                                       //
  4. 4.    // -------                                                       //
  5. 5.    // PHP E-mail Receive Form Electronic Content Text               //
  6. 6.    // File: feedback.php                                            //
  7. 7.    // Version: 1.6 (April 2, 2005)                                  //
  8. 8.    // Description: Processes a web form to read the user input and  //
  9. 9.    //    then send the data to a predefined recipient.  You are     //
  10. 10.    //    free to use and modify this script as you like.            //
  11. 11.    // Instructions:  Go to "<Link removed>".          //
  12. 12.    //                                                               //
  13. 13.    // Center Key Software  *  <Link removed>  *  Dem Pilafian    //
  14. 14.    ///////////////////////////////////////////////////////////////////
  15. 15.     
  16. 16.    // Configuration Settings
  17. 17.    $SendFrom =    "Michael Alexander <myemail@yahoo.com>";
  18. 18.    $SendTo =      "<myemail@yahoo.com>";
  19. 19.    $SubjectLine = "Feedback Submission";
  20. 20.    $ThanksURL =   "<http://www.mydomain/thankyou.html>";  //confirmation page
  21. 21.    $Divider =     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
  22. 22.     
  23. 23.    // Build Message Body from Web Form Input
  24. 24.    $MsgBody = @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n$Divider\n";
  25. 25.    foreach ($_POST as $Field=>$Value)
  26. 26.       $MsgBody .= "$Field: $Value\n";
  27. 27.    $MsgBody .= "$Divider\n" . $_SERVER["HTTP_USER_AGENT"] . "\n";
  28. 28.    $MsgBody = htmlspecialchars($MsgBody);  //make content safe
  29. 29.     
  30. 30.    // Send E-Mail and Direct Browser to Confirmation Page
  31. 31.    mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom");
  32. 32.    header("Location: <http://www.mydomain.com/thankyou.html>");
  33. 33.    ?>
  34.  




I could have also put the wrong information into this code as well. This is just two code snipets from my form. I espescially don't know if the "B1" part is right.
Expand|Select|Wrap|Line Numbers
  1. <form action="feedback.php" method="post">
  2. <input value="Submit" name="B1" type="submit">
  3.  
I have both the php file and the form file saved in the same folder and uploaded to a host that supports php4.1.
Oct 3 '07 #3
Atli
5,058 Recognized Expert Expert
The form looks all right, except that you are missing the </form> closing tag, but I suspect thats because you are only showing us a part of the form.

You should be redirected to the feedback.php page when you click the button. If that isn't happening there is something else going on in the submission page.

If you are getting redirected, but shown noting, make sure the debug messages are tuned on. Also, try changing <?... ?> to <?php ... ?>. The former only works on servers that have been specially configured to work that way. I'd recommend against using the short tag version, it can cause problems in the future.

Also, if there is anything added to the response before you call the header() function, it will not work. Even if it is only a whitespace before the <?php tag.
Oct 3 '07 #4
Michael117
5 New Member
“You should be redirected to the feedback.php page when you click the button. If that isn't happening there is something else going on in the submission page.”

I didn’t quite understand what you meant by this. Are you saying whenever I fill out the form and click submit because I thought that the php file’s whole purpose was to tell the form what to do.

I changed the <?...?> to <?php...?>

I tried the debug message thing and it didn’t change anything, whenever I click on the submit button it still doesn’t take me anywhere or send any email. I am pretty sure I entered this part of it wrong though so that could be it.

Expand|Select|Wrap|Line Numbers
  1. mysql_query($query, $link_id) or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');
  2.  
Here is where I entered that debug code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. error_reporting(E_ALL); 
  3. ini_set('display_errors', True);
  4.  
  5. mysql_query($query, $link_id) or die('<hr />MySQL Error: ' .mysql_error(). '<hr />');
  6.  
  7.  
  8. ///////////////////////////////////////////////////////////////////
  9. // PERFECT                                                       //
  10. // -------                                                       //
  11. // PHP E-mail Receive Form Electronic Content Text               //
  12. // File: feedback.php                                            //
  13. // Version: 1.6 (April 2, 2005)                                  //
  14. // Description: Processes a web form to read the user input and  //
  15. //    then send the data to a predefined recipient.  You are     //
  16. //    free to use and modify this script as you like.            //
  17. // Instructions:  Go to "http://www.centerkey.com/php".          //
  18. //                                                               //
  19. // Center Key Software  *  www.centerkey.com  *  Dem Pilafian    //
  20. ///////////////////////////////////////////////////////////////////
  21.  
  22. // Configuration Settings
  23. $SendFrom =    "Michael Alexander <myemail@yahoo.com>";
  24. $SendTo =      "myemail@yahoo.com";
  25. $SubjectLine = "Feedback Submission";
  26. $ThanksURL =   "http://www.mydomain.com/thankyou.html";  //confirmation page
  27. $Divider =     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
  28.  
  29. // Build Message Body from Web Form Input
  30. $MsgBody = @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n$Divider\n";
  31. foreach ($_POST as $Field=>$Value)
  32.    $MsgBody .= "$Field: $Value\n";
  33. $MsgBody .= "$Divider\n" . $_SERVER["HTTP_USER_AGENT"] . "\n";
  34. $MsgBody = htmlspecialchars($MsgBody);  //make content safe
  35.  
  36. // Send E-Mail and Direct Browser to Confirmation Page
  37. mail($SendTo, $SubjectLine, $MsgBody, "From: Michael Alexander <myemail@yahoo.com>");
  38. header("Location: http://www.mydomain.com/thankyou.html/");
  39. ?>
  40.  
Oct 3 '07 #5
Atli
5,058 Recognized Expert Expert
I didn’t quite understand what you meant by this. Are you saying whenever I fill out the form and click submit because I thought that the php file’s whole purpose was to tell the form what to do.
Not exactly, but I can see where your coming from.

When you submit a form, your browser, along with the form data, is redirected over to the page you define in the action property of the <form> element. In your case feedback.php. There your PHP code is executed and is able to read the form data.
No matter how the feedback.php code is working, you should be redirected to that page.

If you are still on the submission page after hitting the 'submit' button, your form is not working the way it should be, which would indicate a problem with the submission page rather than the feedback page.

So maybe we should take a closer look at the submission page.
Oct 3 '07 #6
Michael117
5 New Member
Ok gotcha,

Well here is the url for my submission page, <Link removed>

I don't know if this helps or not but I typed in <Link removed>, and I went to a page that had this.

Notice: Undefined variable: query in /home/content/m/i/c/michael117/html/feedback.php on line 5

Notice: Undefined variable: link_id in /home/content/m/i/c/michael117/html/feedback.php on line 5

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/m/i/c/michael117/html/feedback.php on line 5

--------------------------------------------------------------------------------
MySQL Error:


And here is the full source code for the form on my submission page
Expand|Select|Wrap|Line Numbers
  1.  <table>
  2.  
  3.         <tbody>
  4.  
  5.           <tr>
  6.  
  7.             <td colspan="2">
  8.         <form action="feedback.php" method="post">              
  9.         <center></center>
  10.  
  11.             </form>
  12.  
  13.             </td>
  14.  
  15.           </tr>
  16.  
  17.           <tr>
  18.  
  19.             <td>Name:</td>
  20.  
  21.             <td><input name="name"></td>
  22.  
  23.           </tr>
  24.  
  25.           <tr>
  26.  
  27.             <td>Email:</td>
  28.  
  29.             <td><input name="from"></td>
  30.  
  31.           </tr>
  32.  
  33.           <tr>
  34.  
  35.             <td>Phone:</td>
  36.  
  37.             <td><input name="custom Phone"></td>
  38.  
  39.           </tr>
  40.  
  41.           <tr>
  42.  
  43.             <td>Company:</td>
  44.  
  45.             <td><input name="custom Company"></td>
  46.  
  47.           </tr>
  48.  
  49.           <tr>
  50.  
  51.             <td>Advertising Type:</td>
  52.  
  53.             <td>
  54.             <select name="custom Advertising Type">
  55.             <option value="Select One" selected="selected">Select
  56. One</option>
  57.             <option value="Banner">Banner</option>
  58.             <option value="Text Ad">Text Ad</option>
  59.             </select>
  60.  
  61.             </td>
  62.  
  63.           </tr>
  64.  
  65.           <tr>
  66.  
  67.             <td>Period:</td>
  68.  
  69.             <td>
  70.             <select name="custom Period">
  71.             <option value="Select One" selected="selected">Select
  72. One</option>
  73.             <option value="One Week">One Week</option>
  74.             <option value="Two Weeks">Two Weeks</option>
  75.             <option value="One Month">One Month</option>
  76.             <option value="Three Months">Three Months</option>
  77.             <option value="Six Months">Six Months</option>
  78.             <option value="One Year">One Year</option>
  79.             </select>
  80.  
  81.             </td>
  82.  
  83.           </tr>
  84.  
  85.           <tr>
  86.  
  87.             <td valign="top">Comments:</td>
  88.  
  89.             <td><textarea name="custom Comments" rows="10" cols="30"></textarea></td>
  90.  
  91.           </tr>
  92.  
  93.           <tr>
  94.  
  95.         <td colspan="2" align="center"><input value="Submit" name="B1" type="submit"></td>
  96.  
  97.         </tr>
  98.  
  99.         </tbody>
  100.       </table>
  101.  
ps - Thanks for being helpful so far I really appreciate it.
Oct 3 '07 #7
helraizer1
118 New Member
With any variables on the php page, have you assigned/defined them?

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $example = $HTTP_POST_VARS['example'];
  3. $seewhatImean = $HTTP_POST_VARS['see']
  4. ?>
  5.  
etc... At the moment the php file doesn't seem to be using anything from the Submission's page, unless you have made the variables with different names that we can't see..

The warning messages say the error is in the code you entered to debug the SQL, but since you don't have and MySQL in your php the variables in the debugger are undefined. If you get rid of the MySQL debugger those messages will go away.
Oct 3 '07 #8
Atli
5,058 Recognized Expert Expert
Yep, there is the problem.

Take a look at the <form> elements. This is how they are in your code:
Expand|Select|Wrap|Line Numbers
  1. <form action="feedback.php" method="post">             
  2.         <center></center>
  3.  
  4.             </form>
  5.  
You are closing the form before you add any <input> elements into it. The <input> elements should be inside the <form>.. </form> tags.

As it is, the submit button does not belong to a <form>, so naturally it will do nothing when you click it.

P.S. The links still violate the posting guidelines so I removed them :)

With any variables on the php page, have you assigned/defined them?

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $example = $HTTP_POST_VARS['example'];
  3. $seewhatImean = $HTTP_POST_VARS['see']
  4. ?>
  5.  
etc... At the moment the php file doesn't seem to be using anything from the Submission's page, unless you have made the variables with different names that we can't see..

The warning messages say the error is in the code you entered to debug the SQL, but since you don't have and MySQL in your php the variables in the debugger are undefined. If you get rid of the MySQL debugger those messages will go away.
He does use it:
Expand|Select|Wrap|Line Numbers
  1. foreach ($_POST as $Field=>$Value)
  2.    $MsgBody .= "$Field: $Value\n";
  3.  
The $HTTP_POST_VARS array is a relic used before PHP4. It has been kept around this long only to assure backwards compatibility. If I am not mistaken, support for this will be removed in PHP6 (correct me if I'm wrong tho).
Use $_POST instead.
Oct 4 '07 #9
Michael117
5 New Member
YES!

It works now!

I knew it would some simple little fix and it was (the <form>...</form> tag was the problem. I put it down after the submit button script and now everything works.


Thank you for all your help guys and have a great day.
Oct 4 '07 #10
Atli
5,058 Recognized Expert Expert
I'm glad you got it working! :)
Don't hesitate to post again if you have any more questions or problems we can help with.
Oct 4 '07 #11

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

Similar topics

5
5347
by: Nelson Minar | last post by:
I'm writing some code to upload photos to Flickr. The Photo Upload API requires documents be POSTed via a multipart/form-data request. I was surprised to learn that Python 2.3's HTTP clients don't...
2
5300
by: John Davis | last post by:
What is the **MOST** obvious reason why will this will fail (it's not syntax or anything specific to the object)? Function Mail(MailerProgram, Message, Subject, Format, FromEmail, ToEmail,...
3
2987
by: Mark Creelman | last post by:
Hello all: How do I convert this ASP mailer script to accept and mail multiple fields of a form. This will do one field only )iMesg.TextBody = Request.Form("body") and it works great. Seems...
2
1717
by: Ciberguy | last post by:
I created a form that collects information from a user via a web page. The form appears to work well - it won't let you submit the form until required data is place in the required fields. I...
3
1767
by: Guy Verville | last post by:
I'm perplexed, I have several forms that seem to be ok, but what is sent by email doesn't contain all the Carriage returns sent. The form contains many fields and is sent as follow:...
1
1625
by: javascript | last post by:
I need to modify a code in Java Script for a Form Mailer page (asp), to be used for online newsletter subscriptions. So long, CDONTS had been playing an important role here, but since SMTP...
2
2007
by: kind1one | last post by:
I am green to PHP and trying to create outside PHP mailer for html form ,i found the script i need but I can't get it to upload more than one file ,since i do not know exactly where to place script...
2
1605
by: carringtonf | last post by:
Okay, I have a form up that worked fine until recently. My hosting (1&1) is denying that they did anything, and that they can't assist me. So I turn to you. Form location -...
12
3794
by: colt28 | last post by:
Ok so I found an ajax contact form script but i can't get the b****** to work. I made a bunch of alterations to it and it didn't work so i replaced everything with the original and it still didn't...
0
7167
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
7208
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
5464
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
4593
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
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
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
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.