simple formmailer - beginner's mistake

the mail() function

Moderators: macek, egami, gesf

Miss_Marple
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Jul 30, 2002 11:27 pm

simple formmailer - beginner's mistake

Postby Miss_Marple » Thu Aug 15, 2002 8:38 am

The else-message won't appear even when the email-field is empty.

<form action="<?php echo $PHP_SELF; ?>" method="post">
Bitte geben Sie Ihren Namen ein: <input type="text" name="Mail"><br><br>
Ihre Nachricht<br>
<textarea name="botschaft" cols="50" rows="5" wrap="soft">
</textarea><br>
<input type="submit" value="Mail abschicken">
</form>
<?php
if (isset($Mail) && $Mail != "") {
if (mail("don_martin@hotmail.com", "Antwort auf Ihre Anfrage!", "$botschaft", "From: $Mail")) {
echo "<p>Danke! Ihre Nachricht wurde weitergeleitet!</p>\n";
}
else {
echo "<p>Leider gab es einen Sendefehler!</p>\n";
}
}
?>

miss marple

elitecodex
New php-forum User
New php-forum User
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA
Contact:

Postby elitecodex » Thu Aug 15, 2002 2:44 pm

Unfortunaly I dont know exactly what to do here. I see some things that I would have done differently, but I dont think it will make it work. This is just what I use for my coding standards.

Your Line:
<form action="<?php echo $PHP_SELF; ?>" method="post">

What I would have done:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

Your Line:
if (mail("don_martin@hotmail.com", "Antwort auf Ihre Anfrage!", "$botschaft", "From: $Mail"))

What I would have done:
if (mail("don_martin@hotmail.com", "Antwort auf Ihre Anfrage!", $botschaft, "From: " . $Mail))

---
Now keep in mind that I dont know how my techniques will work in older versions of PHP, and I dont know how important compactibility is. My only other suggestion is debugging. I have not found any good debuggers for PHP except Zend (but it comes at a price of 250). So just output your variable values and see what they are compared to what they are suppose to be. Another recommendation would be to set your error_reporting value to E_ALL (This will display all errors and warnings).

I dont see any syntax errors, so im sorry that I could not be more help. Best of luck.

Will

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: simple formmailer - beginner's mistake

Postby WiZARD » Thu Aug 15, 2002 10:16 pm

Miss_Marple wrote:The else-message won't appear even when the email-field is empty.

<form action="<?php echo $PHP_SELF; ?>" method="post">
Bitte geben Sie Ihren Namen ein: <input type="text" name="Mail"><br><br>
Ihre Nachricht<br>
<textarea name="botschaft" cols="50" rows="5" wrap="soft">
</textarea><br>
<input type="submit" value="Mail abschicken">
</form>
<?php
if (isset($Mail) && $Mail != "") {
if (mail("don_martin@hotmail.com", "Antwort auf Ihre Anfrage!", "$botschaft", "From: $Mail")) {
echo "<p>Danke! Ihre Nachricht wurde weitergeleitet!</p>\n";
}
else {
echo "<p>Leider gab es einen Sendefehler!</p>\n";
}
}
?>

miss marple


Hi!
try add in your script this:

Code: Select all

  $string = trim($Mail); before if section.


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest