Log in

View Full Version : Contact form



jan24
10-10-2010, 04:32 PM
Hallo,

I got here a contact form.
Although its working for 50%
He atleast sends the mail to mine e-mail and i receive it.
Besides that i can also see the subject of the mail.
Either though i cant see the rest of the mail is total empty.

I have got this contact form from: http://phpeasystep.com/phptu/8.html
I just try to make a simple contact form.
I got 2 files:
- contact.php
- send_contact.php

The files codes are here:
Contact.php

<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><strong>Contact Form </strong></td>
</tr>
</table>

<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send_contact.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Detail</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

send_contact.php

<?php
$subject ="$subject";
$message="$detail";

$mail_from="$customer_mail";
$header="from: $name <$mail_from>";

$to ='mymail@provider.com';

$send_contact=mail($to,$subject,$message,$header);

if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>

If somebody could help me out i would be really thankful :)
Thanks in advance.
Greetz,

Jan24

bluewalrus
10-10-2010, 05:44 PM
That is a bad tutorial. You need to set the variables to be able to send them. Try this code below.



<?php
$subject = $_POST['subject'];
$message= $_POST['detail'];

$mail_from= $_POST['customer_mail'];
$name = $_POST['$name'];
$header="From: $name <$mail_from>";

$to ='mymail@provider.com';

if (mail($to,$subject,$message,$header)) {
echo "We've received your contact information";
} else {
echo "ERROR";
}
?>

prasanthmj
10-11-2010, 03:45 PM
I have got this contact form from...
The code is wrong. It assumes register globals is on.

The link has a free contact form code that you can just 'just plug in'

PHP Contact form tutorial (http://www.html-form-guide.com/contact-form/php-contact-form-tutorial.html)

jan24
10-11-2010, 05:37 PM
Thanks to both of u for your reply
Altough to prasanthmj i rather stick with this code.
Either though it needs some changes but i can build from it and the link you give me is to much script for what i need. Still though thanks :)

To bluewalrus Thanks!
Now more things are working but still not all. The Subject he is sending just like before. But now he also sends the message. But when i try to add more fields to it like 3 fields he doesnt sends at all anymore and get a error.

I changed it likes this i added a line like this at the contact.php:


<tr>
<td>Last name</td>
<td>:</td>
<td><input name="last_name" type="text" id="last_name" size="50"></td>
</tr>
This code is working fine so far.

And added at the send_contact.php this:

$last_name = $_POST['last_name'];
And added at the line the $last_name so he will send it also:

if (mail($to,$subject,$last_name,$message,$header)) {

But then mostly i get a error but still sending email, when i add another field i get a error and dont get a email at all.
Its bit odd to me. To me it looks like he cant send more then 5 variables and i want to send more.

I hope u can help me out with this.
Thanks in advance :)

bluewalrus
10-11-2010, 06:01 PM
The mail php function only takes 4 values you'll need to put the last name into one of the other variables you already have. Do you want it in the subject, the body or the from tag?

http://php.net/manual/en/function.mail.php

This example shows how you'd do it with the from field




$header="From: $name $last_name <$mail_from>";
if (mail($to,$subject,$message,$header)) {

Another example using the "." to concatenation all the values.


$header= "From " . $name . " " . $last_name . " <$mail_from>";

jan24
10-11-2010, 06:04 PM
I got it now all working!! Really great thanks a lot! :D
Although i am using at the moment a hotmail account for testing.
When i test the form i get the email with all the data i entered.

Although it goes into my spam folder with the message: That this email isnt trusted by their SmartScreen-filters and will be deleted after 10 days.

Of course i dont want to get this email into my spam folder how i fix this?

BTW in the form i entered the email bart@hotmail.com

bluewalrus
10-11-2010, 06:15 PM
The spam problem could be because the server sending the email and the domain of the from don't match up. I don't usually use a from address. You can put that in the body of the email and it should be fine or even in the subject.

jan24
10-11-2010, 06:48 PM
Alright i think i will do that then :)
I think mostly all is solved all the rest i can fix out by myself :)
Thanks a lot for your help and time :)
This topic is solved :)