473,385 Members | 1,620 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,385 software developers and data experts.

new to php

This is my first attempt ever at php can anyone glance over this
code segmant and tell me were I am going wrong please

---- HTML ----
<html>
<head>
<title>Email Me</title>
<body>
<p>
</head>
<table width="400">
<tr>
<td>
<form action="email.php" method="POST">
Subject:
<br>
<input type="text" name="subject" size="20" maxlength="30">
<p>
Message:
<br>
<textarea rows="8" name="message" cols="25"></textarea>

<p>
<input type="submit" value="Send">
</form>
</td>
</tr>
</table>
</body>
</html>

------------------------------
----PHP -------
<html>
<body>

<?php
$to = "ot******@aol.com";
$from = "desot******@aol.com";
// $subject = "This is a test email";
// $message = "Dear Desmond,\n\n\n This is just a test email.\n\n
From Chris.";


// $headers = "From: $from\r\n";

$success = mail($to, $HTTP_POST_VARS["subject"],
$HTTP_POST_VARS["message"]);
if ($success)
echo "The email to $to from $from was successfully sent";
else
echo "An error occurred when sending the email to $to from
$from";
?>

</body>
</html>

Jul 17 '05 #1
12 1348
Desmond wrote:
This is my first attempt ever at php can anyone glance over this code
segmant and tell me were I am going wrong please
As I often like to ask when people ask such not well thought out
questions: What was your first indication that it failed? Also, what
have you done in your attempts to debug it?
---- HTML ----
<html>
<head>
<title>Email Me</title>
<body>
<p>
</head>
<table width="400">
<tr>
<td>
<form action="email.php" method="POST">
Subject:
<br>
<input type="text" name="subject" size="20" maxlength="30">
<p>
Message:
<br>
<textarea rows="8" name="message" cols="25"></textarea>

<p>
<input type="submit" value="Send">
</form>
</td>
</tr>
</table>
</body>
</html>

------------------------------
----PHP -------
<html>
<body>

<?php
$to = "ot******@aol.com";
$from = "desot******@aol.com";
// $subject = "This is a test email";
// $message = "Dear Desmond,\n\n\n This is just a test email.\n\n
From Chris.";


// $headers = "From: $from\r\n";

$success = mail($to, $HTTP_POST_VARS["subject"],
$HTTP_POST_VARS["message"]);
if ($success)
echo "The email to $to from $from was successfully sent";
else
echo "An error occurred when sending the email to $to from
$from";
?>

</body>
</html>

--
Headline: Bear takes over Disneyland in Pooh D'Etat!

Jul 17 '05 #2
*** Desmond wrote/escribió (15 Jun 2005 07:43:33 -0700):
This is my first attempt ever at php can anyone glance over this
code segmant and tell me were I am going wrong please
Your main mistake is that you've tagged your usenet message to be ignored.
Subject line should be used to provide a short description of what your
message is about; that way, when there's traffic in the group, it can call
the attention of someone who may have the knowledge to help. Also, you
cannot just paste 50 lines of code and let others figure out what your
problem is. Explain what your want to do and how your code fails to do so.
Error messages are especially helpful.

<body>
<p>
</head>
To begin with, this is not valid HTML. Check http://validator.w3.org/
<form action="email.php" method="POST">
$success = mail($to, $HTTP_POST_VARS["subject"],
$HTTP_POST_VARS["message"]);


$HTTP_POST_VARS is deprecated, use $_POST instead.
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #3
Alvaro G Vicario wrote:
<form action="email.php" method="POST">
$success = mail($to, $HTTP_POST_VARS["subject"],
$HTTP_POST_VARS["message"]);


$HTTP_POST_VARS is deprecated, use $_POST instead.


And filter the subject & message input so there isn't anything nasty in
it before using the submitted info. (In this case, you may want to do
something like strip_tags() on it since it's not an HTML MIME message.)

Best to get in the practice of validating/filtering input and output
from the beginning - event if it isn't necessary. It will save you a lot
of headaches down the road...

--
Justin Koivisto - ju****@koivi.com
http://koivi.com
Jul 17 '05 #4
I have downloaded a tutorial learn php in 6 days. But there is an area
i don't understand. I am
told to use

<form action = "action1.php3" method = "POST">

but how do i asign a php variable to it so I can use the following

$success = mail($to, $subjec, $message);

Please Desmond.

Jul 17 '05 #5
The indication that it failed was there was no email sent even though
it said so. All I want to do is retreave the variables from the html
page and send an email.

this is it. I am new to php but ok on html

http://www.des-otoole.co.uk/email.html

Jul 17 '05 #7
Desmond wrote:
The indication that it failed was there was no email sent even though
it said so.
There that wasn't that hard was it. In the future always include what
actually happened, error message, etc. - otherwise we are just guessing.

Now did you think to stop and check to make sure what you put in was
correct? By that I mean you used certain variables but were you sure
that they contained what you thought they should contain? Adding display
like debugging statements is always helpful.
All I want to do is retreave the variables from the html page and send
an email.
Yes. Break the problem down and work on a small subset of the problem.
Validate your assumptions before proceeding further. Another poster
already hinted to the probable problem. IOW verify that you are doing
"A" properly first before attempting "B". "A" here = "retrieve the
variables from the html page". Are you sure you've retrieved them properly?

Instead of plodding onward to emailing them how about simply displaying
them to make sure they are correct first. Your email.php can instead of
emailing simply write out HTML displaying the contents of what is passed
in. Once you're sure that's correct then go onward.

So instead of:

<html>
<body>

<?php
$to = "ot******@aol.com";
$from = "desot******@aol.com";
// $subject = "This is a test email";
// $message = "Dear Desmond,\n\n\n This is just a test email.\n\nFrom Chris.";
// $headers = "From: $from\r\n";

$success = mail($to, $HTTP_POST_VARS["subject"],
$HTTP_POST_VARS["message"]);
if ($success)
echo "The email to $to from $from was successfully sent";
else
echo "An error occurred when sending the email to $to from $from";
?>

</body>
</html>

Try:

<html>
<body>

<?php
$to = "ot******@aol.com";
$from = "desot******@aol.com";

$subject = $_POST["subject"];
$message = $_POST["message"];

print "subject = '$subject'<br>";
print "message = '$message'<br>";

if (mail($to, $subject], $message)) {
echo "The email to $to from $from was successfully sent";
} else {
echo "Unable to send message";
}
?>

</body>
</html>

Additionally read up on the documentation about the function you are
using - mail - http://us3.php.net/manual/en/function.mail.php. Also
refer to http://us3.php.net/manual/en/ref.mail.php, especially the user
comments about specifying a proper From address.
this is it. I am new to php but ok on html
I'd say your html could use a little work too! ;-)
http://www.des-otoole.co.uk/email.html
--
Too many freaks, not enough circuses.

Jul 17 '05 #8
Can someone please tel me the equivelent in PHP of this vbscript

Response.Redirect "acknowledge".html Thanks

Jul 17 '05 #9
*** Desmond wrote/escribió (16 Jun 2005 02:58:54 -0700):
Can someone please tel me the equivelent in PHP of this vbscript

Response.Redirect "acknowledge".html Thanks


header('Location: http://' . $_SERVER['HTTP_HOST] . '/acknowledge".html');
exit;
Although it does work with a relative location, I believe HTTP v1.1
requires a full URL.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #10
On Wed, 15 Jun 2005 15:11:25 GMT,
Justin Koivisto<ju****@koivi.com> wrote:
Alvaro G Vicario wrote:
<form action="email.php" method="POST">
$success = mail($to, $HTTP_POST_VARS["subject"],
$HTTP_POST_VARS["message"]);
$HTTP_POST_VARS is deprecated, use $_POST instead.


And filter the subject & message input so there isn't anything nasty in
it before using the submitted info. (In this case, you may want to do
something like strip_tags() on it since it's not an HTML MIME message.)


So, if I wanted to mail the author and point out that
"the <body> and </head> tags are incorrectly nested", he'd
read that "the and tags are incorrectly nested". That's
worse than useless.
Best to get in the practice of validating/filtering input and output
from the beginning - event if it isn't necessary. It will save you a lot
of headaches down the road...


Yes, but blindly deleting content for no apparent
reason is not much of an improvement.
--n
Jul 17 '05 #11
You could use html_entities() instead of strip_tags():
http://www.php.net/html_entities
Then if you send the email as an HTML email the reader will display it
right. Or if you are confortable with HTML entities you could still
just send it as a plain text email. I can't see anything wrong with
that code, but like Andrew says, break it down into smaller parts.
BTW, instead of writing $HTTP_POST_VARS["message"] you could just write
$_POST['message']. Means the same thing.

Jul 17 '05 #12
fool

Jul 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.