473,408 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Problem with php code for a mail contact form

Hello,

I am new to PHP code and I have copied the following code from the internet to create a contact page on my web site.


Expand|Select|Wrap|Line Numbers
  1. <?
  2. $subject="from ".$_GET['your_name'];
  3. $headers= "From: ".$_GET['your_email']."\n";
  4.  $headers='Content-type: text/html; charset=iso-8859-1';
  5. mail("<emailremoved>", $subject,"
  6. <html>
  7. <head>
  8.  <title>Contact letter</title>
  9. </head>
  10. <body>
  11.  
  12. <br>
  13.   ".$_GET['message']."
  14. </body>
  15. </html>" , $headers);
  16. echo ("Your message was successfully sent";
  17. ?>
  18. <script>
  19.     resizeTo(300, 300)
  20.     //window.close()
  21. </script>
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. However when the script is run I get the following error
  30.  
  31. ".$_GET['message']." " , $headers); echo ("Your message was successfully sent!"); ?>
  32.  
Can any one help please?
Nov 14 '08 #1
11 1893
Markus
6,050 Expert 4TB
Sure, we'd love to help, but in order for that to happen you've got to do a few things:
  • Use [code] tags when supplying code
  • Provide us with *all* relevant information - the info you gave is next to nothing, and certainly not enough to help you with
  • Tell us the errors
  • Tell us what didn't happen
  • Tell us what you wanted to happen
  • Tell us what *did* happen

Also, do not post email addresses.

Please read the Posting Guidelines to avoid these errors and others.

Moderator.
Nov 14 '08 #2
Sorry


The error message is at the end of the code, On my email form I input a name, email address and text. Then I press the submit button and get a window opening 300X 300 with the text listed at the end of the code. No email is sent. I am testing the code on a laptop using XAMPP. The variable name and email address are listed at the top of the window so they look to be set OK . The prblem looks to be with the email comand .......?


Thanks
Nov 14 '08 #3
maheswaran
190 100+
see

echo ("Your message was successfully sent";

is not closed...
Nov 15 '08 #4
Thanks for the response,

I have changed the line echo ("your message was successfully sent!");
However I get the same problem but your point about closing () would the line
mail("XXX@XXXXX", $subject," need to be changed / closed

Thanks
Nov 15 '08 #5
Markus
6,050 Expert 4TB
Is this a .php file ?
Is your server running PHP?

If you view of the source code of the page, what is the output?
Nov 15 '08 #6
nathj
938 Expert 512MB
Thanks for the response,

I have changed the line echo ("your message was successfully sent!");
However I get the same problem but your point about closing () would the line
mail("XXX@XXXXX", $subject," need to be changed / closed

Thanks
Looking through the code I can see that the line you mention is actually closed further down with the code:
Expand|Select|Wrap|Line Numbers
  1. </HTML>",$headers);
  2.  
(something similar, I can't see it while I type this). Basically this code is trying to set up an HTML email message and send it using the normal mail functions in PHP.

I would either, ditch the HTML part and have a simple text only email, or read up on headers to make sure they are correct. (Google PHP mail ) the top result should help)

Either way I would build up the message in a separate variable first and then include that variable as the message parameter.

Cheers
nathj
Nov 17 '08 #7
change

echo ("Your message was successfully sent";

to

echo ("Your message was successfully sent");

this may solve your problem. If it does not solve your problem let me know again.
Nov 18 '08 #8
maheswaran
190 100+
Please check ur server which it allow short tag function <? and ?>

else u need to put <?php ?>

Try with this

Start php lie

<?php
<!-- ur codes -->
?>
Nov 18 '08 #9
nathj
938 Expert 512MB
Please check ur server which it allow short tag function <? and ?>

else u need to put <?php ?>

Try with this

Start php lie

<?php
<!-- ur codes -->
?>
The simple solution on this one is to always use the full tag <?php ... ?> and not the short tags, no need to check the server, just do it.
nathj
Nov 18 '08 #10
r035198x
13,262 8TB
If you are new to PHP then you should read the PHP tutorial first. There is no point in just downloading some code and trying to automagically turn it into working code without understanding the language.
Nov 18 '08 #11
nathj
938 Expert 512MB
If you are new to PHP then you should read the PHP tutorial first. There is no point in just downloading some code and trying to automagically turn it into working code without understanding the language.
That's the best advice you've been given so far.

Here's the tutorial that got me started: W3Schools PHP tutorial the other site that will prove invaluable is this one.

Cheers
nathj
Nov 18 '08 #12

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

Similar topics

6
by: Jeff Dunnett | last post by:
Hello, I have written the following HTML Form: <html><head><title>Survey</title></head> <body bgcolor="black" text="white" link="#f6b580" vlink="#c0c0ff"> <img src="logo.gif" width="324"...
15
by: Steve Horrillo | last post by:
I can't figure out why this script won't insert the subject in the email and why can't I control the font and size being used? I'm not sure where to post this. Let me know where if this is OT. ...
5
by: Neil McDermott | last post by:
Hello, I hope someone can help. I use a php form to process contact forms on my web sites. Recently I have been receiving lots of strange data coming through the contact forms like this : ...
2
by: shapper | last post by:
Hello, I have a contact form in my web site which is working just fine on my computer! When I uploaded my web site to my hosting server I get an error when I SUBMIT my form, i.e., when I...
3
by: mcchristie | last post by:
hi all, i've never used ASP before, but am proficient with html / css all i want to do is add a feedback form to a site. i have the form all set up as follows: <form method="post"...
20
by: Pete Marsh | last post by:
Wondering if anyone can see an error with this script. I get a server configuration error. THat could mean a module is not being loaded, but maybe there's a syntax error here, can anyone spot it?...
2
by: kgrenier12 | last post by:
I'm new at using php. I am creating a basic html "contact us" form using php to send the data securely via email. I posted the form and the screen turns blank when I hit the "submit" button. ...
12
by: Twayne | last post by:
Hi, I can't get the following code snippet to stop throwing errors except to modify it exactly as shown here by adding the single quote to the end of the first line and commenting out all but...
2
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my...
2
by: Ecot | last post by:
Hi all, I have not got any php knowledge and I have found a php code on the net and using it to send e-mail from a web html form.So far the form and the code works fine. I have the following php...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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...
0
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...

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.