Here is my code..
// Save form content in variables
$name = $_POST['name'];
$mail = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// echo "$name" is showing the name here...
// Check if any field are empty
if((!$name = empty($name))||
(!$mail = empty($mail))||
(!$subject = empty($subject))||
(!$message = empty($message))){
// Here is $name empty, even when the form field contains data.. Why?
echo "From: $name<br />Email: $mail<br />Subject: $subject<br
/>Message:<br />$message<br />";
} else {
echo "<p>Please fill in information in all fields!</p>";
return false;
}
Thanks for all help, once again!
Kind Regards,
Karl
if((!$name = empty($name))||
This assigns the value of true or false to $name, depending on the
previous contents of $name.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
Use if (!empty($name)||!empty($mail).....
Now it reads (afaik): make not $name equal to the boolean (empty($name))
and that will be evaluated (if name="") as: true=true while $name=false
so !$name will be true....
Or perhaps as: not ($name=empty($name)) and that is as: not
($name=false) and at last not (false) and that happens to be true. In
the meanwhile $name is set to false.
Better use if (empty($name)||empty($mail)||.... to detect is one field
is empty.
--
]-[oRus
www.smallsystemservice.nl
= is an assignment operator
== is an equality operator
MG
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>New document</title>
<meta name="generator" content="TSW phpCoder 2008" />
</head>
<body>
<form action="index.php" method="post">
<p>Name:<br /><input type="text" name="name" size="50" maxlength="50"
value=" . <?php $_POST['name']; ?> ." /></p>
<p>E-mail:<br /><input type="text" name="email" size="50" maxlength="80"
/> </p>
<p>Subject:<br /><input type="text" name="subject" size="50"
maxlength="50" /></p>
<p>Message:<br /><textarea cols="50" rows="10"
name="message"></textarea></p>
<p><input type="reset" value="reset"/> <input type="submit"
name="prayer_request" value="Send" /></p>
</form>
<?php
if(isset($_POST['prayer_request'])){
// Save form content in variables
$name = $_POST['name'];
$mail = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Check if any field are empty
if(empty($name)){
echo "<p>Name have to be written!</p>";
return false;
}
if(empty($mail)){
echo "<p>Have you forgot to write your email address?</p>";
return false;
}
if(empty($subject)){
echo "<p>You need to write a subject for your message!</p>";
return false;
}
if(empty($message)){
echo "<p>Please write down a message to us!</p>";
return false;
}
// Check the fields that enough characters are written
// in each of them
if(strlen($name) < 2){
echo "You need at least two characters in the Name field";
return false;
}
if(strlen($mail) < 8){
echo "Please enter your email address!";
return false;
}
if(strlen($subject) < 3){
echo "You have not write a subject for your message. Use at least 3
letters!";
return false;
}
if(strlen($message) < 10){
echo "Please write down a message to us. Use at least 10 characters in
it!";
return false;
}
// Strip HTML codes from the input fields
$name = strip_tags($name);
$mail = strip_tags($mail);
$subject = strip_tags($subject);
$message = strip_tags($message);
// Check the Email address.
// Taken from article at
//
http://www.totallyphp.co.uk/code/validate_an_email_address_using_regular_expressions.htm
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",
$mail)) {
// echo "Valid email address.";
$mail;
}
else {
echo "Invalid email address.";
return false;
}
// Convert HTML characters to entity
// if the message still contains it
$name = htmlentities($name);
$mail = htmlentities($mail);
$subject = htmlentities($subject);
$message = htmlentities($message);
// If message contains æøå/ÆØÅ that is translated above
// by htmlentities, then translate the letter back
$name = str_replace("Æ", "Æ", $name);
$name = str_replace("Ø", "Ø", $name);
$name = str_replace("Å", "Å", $name);
$name = str_replace("æ", "æ", $name);
$name = str_replace("ø", "ø", $name);
$name = str_replace("å", "å", $name);
$subject = str_replace("Æ", "Æ", $subject);
$subject = str_replace("Ø", "Ø", $subject);
$subject = str_replace("Å", "Å", $subject);
$subject = str_replace("æ", "æ", $subject);
$subject = str_replace("ø", "ø", $subject);
$subject = str_replace("å", "å", $subject);
$message = str_replace("Æ", "Æ", $message);
$message = str_replace("Ø", "Ø", $message);
$message = str_replace("Å", "Å", $message);
$message = str_replace("æ", "æ", $message);
$message = str_replace("ø", "ø", $message);
$message = str_replace("å", "å", $message);
// Get the content in ma.txt file
$myFile = "ma.txt";
$handle = fopen($myFile, 'r');
$Data = fread($handle, 99999999);
fclose($handle);
// Replace \r\n with ,
$Data = str_replace("\r\n",",", $Data);
// Send it
$to = "Karl@localhost, ";
$from = "From: $mail";
$subject = "$subject";
$body = "From: $name\nEmail: $from\nSubject:
$subject\nMessage:\n$message";
$headers = 'Content-type: text/plain; charset=utf-8' . "\r\n";
$headers .= "$from \n";
// Example taken from PHP Manual
$arr = array("$Data");
reset($arr);
// Take all values in $Data that is Saved in $arr and
// save them in $value
while (list(,$value) = each($arr)) {
// Save contents in $headers
$headers .= "Bcc: $value";
}
//$header .= "Karl@localhost";
mail($to, $subject, $body, $headers);
echo "<p>Message is sent</p>";
}
?>
<h3>Feature of this PHP Application</h3>
<p>
<ul>
<li>It collect message from users and send it to different e-mail
addresses that is written in a regular textfile</li>
<li>It check if any fields in the HTML form is empty</li>
<li>It check if a minimum of characters is written in each field</li>
<li>It check if the email address given, have correct syntax</li>
<li>It translate HTML tags into entity code</li>
<li>It support UTF-8 characters</li>
<li>It support ÆØÅ - æøå.
(Norwegian language)</li>
<li>It support unlimit number of emails that can receive the content
from the form!</li
<li>No need for Databases!</li>
</ul>
</p>
</body>
</html>
Do you know about a web pages were they talk about how to check headers
for error? Or can you give me a tip about how to start?
Thanks for all your help! I am very thankful for ut. This is just a
learning project and when it is done I will use it on a private server
not connected to the web... Well, if I can make it good enough, I give
it away as freeware under GNU of course... But I guess I have to learn a
lot more before that is actually!
Kind Regards,
Karl-Arne
> $message = str_replace("Æ", "Æ", $message);
> $message = str_replace("Ø", "Ø", $message);
> $message = str_replace("Å", "Å", $message);
> $message = str_replace("æ", "æ", $message);
> $message = str_replace("ø", "ø", $message);
> $message = str_replace("å", "å", $message);
Did you know that str_replace will take arrays?
--
Geoff Berrow (Put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs www.4theweb.co.uk/rfdmaker
Karl
Try an email-related newsgroup.
> Thanks for all your help! I am very thankful for ut. This is just a
> learning project and when it is done I will use it on a private server
> not connected to the web... Well, if I can make it good enough, I give
> it away as freeware under GNU of course... But I guess I have to learn a
> lot more before that is actually!
>
> Kind Regards,
> Karl-Arne
A lot of other problems, also. First of all, don't use eregxxx()
functions - they have been deprecated in favor of the preg_xxx()
functions. Also, your test will reject a large number of valid email
addresses (as a simple example .museum domains) while accepting a large
number of illegal addresses (i.e. .xyz domain, which doesn't exist). It
also doesn't know if the email is actually valid or not - but you can't
test for that in your code.
I also have no idea why you're using htmlentities() in your code -
you're not sending html, so it's unnecessary.
htmlspecialchars_decode() might also be worth a look.
Micha
OK.. I shall check the manual and google to see how to do it. Thanks...
> functions. Also, your test will reject a large number of valid email
> addresses (as a simple example .museum domains) while accepting a large
> number of illegal addresses (i.e. .xyz domain, which doesn't exist). It
> also doesn't know if the email is actually valid or not - but you can't
> test for that in your code.
I know that in Perl is it possible to connect to DNS servers to check if
a domain/address is valid. Is that possible to do in PHP too? If so: How
do I that?
>
> I also have no idea why you're using htmlentities() in your code -
> you're not sending html, so it's unnecessary.
>
>
I am using htmlentities because of the Norwegian letters æøå - ÆØÅ.
Other HTML code are stripped by strip_tags earlier in the program.
I have also try html_entity_decode() to translate it back but that did
not work.
Then I tried htmlspecialchars_decode but that too did not work out.
Therefore I still use str_replace()
Karl
You can see if a domain is valid. But there is no way you can tell for
sure if an email address is valid, in any language.
>>
>> I also have no idea why you're using htmlentities() in your code -
>> you're not sending html, so it's unnecessary.
>>
>>
> I am using htmlentities because of the Norwegian letters æøå - ÆØÅ.
> Other HTML code are stripped by strip_tags earlier in the program.
>
You are not sending html.
> I have also try html_entity_decode() to translate it back but that did
> not work.
> Then I tried htmlspecialchars_decode but that too did not work out.
> Therefore I still use str_replace()
>
> Karl
Those are used with html - which is why they have "html" in their names.
You are not sending html!