Contact Form Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SLaY
Forum Newbie
Posts: 4
Joined: Wed May 05, 2010 6:12 am

Contact Form Problem

Post by SLaY »

Hi guys, I want to do a contact form but I'm beginning now to learn php, so I follow a tutorial, and I think that everything is correct:

HTML Form:

Code: Select all

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<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>
</body>
</html>
PHP:

Code: Select all

<?php
// Contact subject
$subject ="$subject";
// Details
$message="$detail";

// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";

// Enter your email address
$to ='slay.tiago@gmail.com';

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

// Check, if message sent to your email
// display message "We've received your information"
if($send_contact){
	echo "We've received your contact information";
}
else {
	echo "ERROR";
}
?>
This is a very simple form and I think that everything is correct, but when I test it at my host, although the success phrase appears (We've received your contact information) I don't receive nothing at my email, does anyone know where is the problem ?

Tks in advance
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

Re: Contact Form Problem

Post by rahulzatakia »

Hi, if you are sending mail from localhost, then it will be not send.. And you have error in PHP code file, you need to use $_POST[''] to get the value from form. I have made changes in your code so just check out..

Code: Select all


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

// Mail of sender
$mail_from=$_POST["$customer_mail"];
// From
$header="from: $_POST['name'] <$_POST['mail_from']>";

// Enter your email address
$to ='slay.tiago@gmail.com';

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

// Check, if message sent to your email
// display message "We've received your information"
if($send_contact){
        echo "We've received your contact information";
}
else {
        echo "ERROR";
}
?>

SLaY
Forum Newbie
Posts: 4
Joined: Wed May 05, 2010 6:12 am

Re: Contact Form Problem

Post by SLaY »

Tks for ur attention, i will try.

I'm not trying to use it from localhost, i'm using a online host.
SLaY
Forum Newbie
Posts: 4
Joined: Wed May 05, 2010 6:12 am

Re: Contact Form Problem

Post by SLaY »

I had to change this following line:

$header="from: $_POST[name] <$_POST[mail_from]>";

cuz it was appearing the following error: unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

And I still do not receive the email, i'm testing it here: http://s2.com.pt/EduardoBicalho/test4/contact.php

I cant understand why, I did a flash contact form with php using that host and everything is ok, but with html i can't do it !
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

Re: Contact Form Problem

Post by rahulzatakia »

Hi, i am using with html only and its working fine with me...
can you send me your php and html codes, so that i can review it and fine the exact error...
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Contact Form Problem

Post by Apollo »

SLaY wrote:I cant understand why, I did a flash contact form with php using that host and everything is ok, but with html i can't do it !
What happens if you put a separate test.php on there with only this:

Code: Select all

<?php
$fromAddress = "your.address@somewhere.com";
$sent = mail( "your.momma@anywhere.com", "Test", "Hi mum, this is a test messge!", "From: $fromAddress\r\n", "-f$fromAddress" );
print($sent ? "Hooray!" : "Nope...");
?>
If you browse to this php, what do you get?
SLaY
Forum Newbie
Posts: 4
Joined: Wed May 05, 2010 6:12 am

Re: Contact Form Problem

Post by SLaY »

Ok I think I know what was the problem.

My host which is www.s2.com.pt if I use the contact form to send the form to my gmail it doesn't work, but if i do it to my s2.com.pt email (tiago@s2.com.pt) it works !

So the host can close sending the forms to the other emails other that the host itself ?
Post Reply