Page 1 of 2
PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 6:55 am
by oliver23
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi
I have a problem with my simple PHP Mailform. Since I moved it on a new server it doesen't work anymore. Maybe it's another PHP Version, I don't know. The mail sending works, but I don't get the content. Can someone help?
It looks like that:
Code: Select all
<?
/* Brief generieren und versenden */
$z = 1;
$z++;$b[$z]="firma :".$firma."\n";
$z++;$b[$z]="realname :".$realname."\n";
$z++;$b[$z]="senderemail :".$senderemail."\n";
$letter = implode($b,"");
/* Email an Betreiber der Site */
mail("name@email.ch","Kontaktformular",$letter,"from:$senderemail");
?>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 7:16 am
by aerodromoi
oliver23 wrote:Hi
I have a problem with my simple PHP Mailform. Since I moved it on a new server it doesen't work anymore. Maybe it's another PHP Version, I don't know. The mail sending works, but I don't get the content. Can someone help?
It looks like that:
Code: Select all
<?
/* Brief generieren und versenden */
$z = 1;
$z++;
$b[$z]="firma :".$firma."\n";
$z++;
$b[$z]="realname :".$realname."\n";
$z++;
$b[$z]="senderemail :".$senderemail."\n";
$letter = implode($b,"");
/* Email an Betreiber der Site */
mail("name@email.ch","Kontaktformular",$letter,"from:$senderemail");
?>
You're relying on register_globals on. You'll have to switch to the superglobal post array.
btw:
+ How about using the pre-increment operator (++$z) instead of filling multiple lines?
+ Don't put the email address of the sender in the mail header unless you've validated it.
+ Even though implode accepts the arguments in any order, I'd recommend using implode("",$b).
Posted: Sat Jul 15, 2006 7:17 am
by xeno439
Is the new server running a different version of PHP? PHP 5 or something?
Posted: Sat Jul 15, 2006 7:27 am
by aerodromoi
xeno439 wrote:Is the new server running a different version of PHP? PHP 5 or something?
The default value for register_globals has been "off" since 4.2.0 (which means a few years back).
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 7:52 am
by oliver23
aerodromoi wrote:
You're relying on register_globals on. You'll have to switch to the superglobal post array.
btw:
+ How about using the pre-increment operator (++$z) instead of filling multiple lines?
+ Don't put the email address of the sender in the mail header unless you've validated it.
+ Even though implode accepts the arguments in any order, I'd recommend using implode("",$b).
Thanks for your help. Yes it is PHP5 now!
But I still doesen't get it work. How should it look the way you recommend? Sorry, I'm a PHP Newbie.
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 8:38 am
by aerodromoi
Code: Select all
<?php
// fetch the variables from the post array
$firma = $_POST['firma'];
$letter = $_POST['letter'];
$realname = $_POST['realname'];
$senderemail = $_POST['senderemail'];
?>
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 9:24 am
by oliver23
Sorry, I still don't get it. I can't believe it, the old PHP was much easier. Even I search for google I find only 2 pages forms
What I have now ist the following, and the good thing is I see the from email now. But not the content.
Code: Select all
<?php
// fetch the variables from the post array
$firma = $_POST['firma'];
$letter = $_POST['letter'];
$realname = $_POST['realname'];
$senderemail = $_POST['senderemail'];
/* Email an Betreiber der Site */
mail("name@domain.ch","Kontaktformular",$letter,"from:$senderemail");
?>
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 9:36 am
by aerodromoi
oliver23 wrote:Sorry, I still don't get it. I can't believe it, the old PHP was much easier.
And potentially exploitable.
You might want to take a look at this article:
http://www.jellyandcustard.com/2006/02/ ... on-in-php/
oliver23 wrote:What I have now ist the following, and the good thing is I see the from email now. But not the content.
Looks like a misspelt variable. What's the html sourcecode?
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 9:45 am
by oliver23
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
this ist my html form:
[syntax="html"]<head>
<title>Untitled Document</title>
</head>
<body>
<h2>Ihre Anfrage ist uns willkommen!</h2>
<p>Was können wir für Sie tun?</p>
<form method="post" action="senden.php" name="Kontaktformular">
<h2>Ihre Angaben</h2>
<p></p>
<table width="525" border="0" cellspacing="1" cellpadding="0">
<tr>
<td valign="top" width="100" class="tabdunkel">Firma
</td>
<td valign="top" class="tabdunkel">
<input type="text" name="firma" class="inputfeld" />
</td>
</tr>
<tr>
<td valign="top" width="100" class="tabdunkel">Name *
</td>
<td valign="top" class="tabdunkel">
<input type="text" name="realname" class="inputfeld" />
</td>
</tr>
<tr>
<td valign="top" width="100" class="tabdunkel">E-Mail *
</td>
<td valign="top" class="tabdunkel">
<input type="text" name="senderemail" class="inputfeld" />
</td>
</tr>
</table>
<p><input type="submit" name="submit" value="Senden" class="button" /></p>
</form>
</body>
</html>
feyd | Please use[/syntax]Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 9:51 am
by aerodromoi
oliver23 wrote:
What I have now ist the following, and the good thing is I see the from email now. But not the content.
Because there is no such thing as a textarea for any kind of message in your html form.
You've only got three input fields (for the name, the company and an email address).
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 10:03 am
by oliver23
aerodromoi wrote:
Because there is no such thing as a textarea for any kind of message in your html form.
You've only got three input fields (for the name, the company and an email address).
Yes, all I want is to send an Email with this 3 Information to my emailadress:
Name: Content
Company: Content
Email: Content
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 10:22 am
by aerodromoi
oliver23 wrote:aerodromoi wrote:
Because there is no such thing as a textarea for any kind of message in your html form.
You've only got three input fields (for the name, the company and an email address).
Yes, all I want is to send an Email with this 3 Information to my emailadress:
Name: Content
Company: Content
Email: Content
Code: Select all
<?php
// fetch the variables from the post array
$firma = $_POST['firma'];
$realname = $_POST['realname'];
$senderemail = $_POST['senderemail'];
$recipient = "name@domain.ch";
$subject = "Kontaktformular";
$letter = "Email: " . $senderemail . "\n";
$letter .= "Firma: " . $firma . "\n";
$letter .= "Name: " . $realname;
$header = "X-Mailer: PHP " . phpversion();
// check whether all fields have been filled in
if (empty($firma) || empty($realname) || empty($senderemail)){
print("Sorry, all fields are required!");
}
else{
$result = @mail($recipient,$subject,$letter,$header);
$result ? print ("Thanks!") : print ("An error occurred!");
}
?>
I've removed the email address of the sender from the header tag as it is likely to be exploited without validation.
ps: Man kann auch aneinander vorbeireden

Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 10:42 am
by oliver23
aerodromoi wrote:ps: Man kann auch aneinander vorbeireden

Vielen vielen Dank! It works now! I can't believe, I spend 6 hours for that.
Great help, great forum thanks!
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 10:49 am
by aerodromoi
Code: Select all
<?php
// fetch the variables from the post array
$firma = $_POST['firma'];
$realname = $_POST['realname'];
$senderemail = $_POST['senderemail'];
$recipient = "name@domain.ch";
$subject = "Kontaktformular";
$letter = "Email: " . $senderemail . "\n";
$letter .= "Firma: " . $firma . "\n";
$letter .= "Name: " . $realname;
if (ereg('(cc\:|bcc\:|to\:)', strtolower($senderemail))){
$header = "X-Mailer: PHP " . phpversion();
}
else{
$header = "From: " . $senderemail;
}
// check whether all fields have been filled in
if (empty($firma) || empty($realname) || empty($senderemail)){
print("Sorry, all fields are required!");
}
else{
$result = @mail($recipient,$subject,$letter,$header);
$result ? print ("Thanks!") : print ("An error occurred!");
}
?>
Just to get you started: I've modified the code somewhat to check whether someone has tried to insert additional to/cc/bcc fields.
Gern geschehen!
Re: PHP Mailform dosen't work anymore
Posted: Sat Jul 15, 2006 11:04 am
by oliver23
aerodromoi wrote:
Just to get you started: I've modified the code somewhat to check whether someone has tried to insert additional to/cc/bcc fields.
Gern geschehen!
Perfekt!
One more question, is it possible to forward it to another site (danke.html) if the sending was okay? A redirect instead of