473,624 Members | 2,069 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 2042
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

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

Similar topics

5
5373
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 support this form of POSTs. There is support in cgi.py, for servers. There are some implementations of multipart/form-data on ASPN: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 urllib2_file seems to meet my needs, but I'm not...
2
5309
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, ReplyTo, FromName, ToName, MailerPath, BCCEmail, Attachement) Set Mailer = Server.CreateObject("Persits.MailSender") if NOT isObject(Mailer) Then Mail = false Exit function
3
2993
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 pretty simple, but I am missing it. NOTE: Server uses "CDO" ONLY. (Not CDONTS)
2
1728
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 receive the email from the form via the ISP but the data collected from the form is not there. Where did it go? Here is a copy of the code I am using - It's standard. <!--- mailer.asp --->
3
1783
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
1630
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 relay restrictions have been implemented by my web hosting company to avoid any ABUSE (phishing/spoofing etc. ) using their servers, the code of my page needs to be changed (CDONTS will no longer work). So, I need a sample code without using...
2
2013
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 request for file2-file10 as well as the exact line to place extension control and size limit ,SOS , any help would be aprishiated the mailer script: <?php if (strpos($_SERVER, $_SERVER)>7 || !strpos($_SERVER, $_SERVER)) ...
2
1612
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 - www.eqxstructuring.com/contacts.html-the page loads and says that there is an "Object Expected at Line 82 Char 1" but there is no problem with my form code... I think? Below is the code for the form action script (eqxcontact.asp)Set Mail =...
12
3822
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 work...dunno why, but anyhow. The form appears after a delay on the page in a hidden DIV. The original form just had name, email and message, but i have to add a few questions to it so i did and i also added some code from another script i found to...
0
8174
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8624
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7164
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
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 we have to send another system
1
1786
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.