Jump to content

[SOLVED] Email forum information - please help


ahazin

Recommended Posts

Hi guys, i was wondering if you could please help me ive spent like 8h on this and i really cant get it to work and im getting frustrated.

 

Im making a website and on my feedback page i have a forum with 2 text boxes called name_field and email_field then i also have a text area called message.  The settings of my fourm are as follows:

 

form name="form1" method="post" action="contact.php"

 

In the contact.php file i have the following code:

 

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

 

<body>

 

<?php

if(isset($_POST['submit'])) {

$to = "lucealmighty@hotmail.co.uk";

$subject = "Please work";

$name_field = $_POST['name'];

$email_field = $_POST['email'];

$message = $_POST['message'];

 

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

 

echo "Data has been submitted to $to!";

mail($to, $subject, $body);

} else {

echo "sorry there has been an error please try again"; ;

}

?>

 

 

 

</body>

</html>

 

What i want is when the user fills in the forum and presses the submit button that the information will get sent to my email address and if so a message is displayed stated it has been submitted otherwise stating there was an error.  For the life of me i cant get the code to work and was just wondering if anyone would be so kind as to help me, i would really really appreciate it.  Thank you.

Link to comment
Share on other sites

I was simply running it from the c drive  but yes plans are on the way to get a server which supports PHP.  Judging by what you are saying it would need to be up on the server before it would work.  Perhaps I was being stupid thinking it would work from the c drive?

 

Sorry for my stupidity if thats the case lol, im pretty new to PHP.

Link to comment
Share on other sites

Revraz, i got the php server up and running and i got your section of code to email me and work as intended however im still having a little trouble with my own.  When i have it hooked up to the code I have in my first page I simply get a page saying "Data has been submitted to !" and nothing ends up in my email address.  Was just wondering if you would know what would be causing this problem? 

 

Im maybe just doing something stupid and thats why its not working.

Link to comment
Share on other sites

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

 

<body>

 

<?php

if(isset($_POST['submit'])) {

$to = "lucealmighty@hotmail.co.uk";

$subject = "Form Tutorial";

$name_field = $_POST['name'];

$email_field = $_POST['email'];

$message = $_POST['message'];

 

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

 

echo "Data has been submitted to $to";

mail($to, $subject, $body);

} else {

echo "Data has been submitted to $to!"; ;

}

?>

 

 

 

</body>

</html>

 

That is the entire code i am using at the minute.  Thanks for taking a look.

Link to comment
Share on other sites

try this mail code all on it's own

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);


$email = "lucealmighty@hotmail.co.uk"; 
$subject = "Form Tutorial"; 
$name = $_POST['name']; 
$message = "hello, this is a test;


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$name.' <'.$email.'>,' . "\r\n"; //This is the TO name and Email
$headers .= 'From: Adam<lala@lala.com>' . "\r\n"; // This is YOUR name and email

$result = mail($email, $subject, $message, $headers);
if($result)
{
echo "Mail has been sent";
}
else
{
echo "Mail Failed";
}


?>

 

 

Link to comment
Share on other sites

Thanks for taking the time to right that , with that code i get the following error: Parse error: syntax error, unexpected T_STRING in test.php on line 12

 

Alternatively i have tried a different type of code:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<?php 
$to = "lucealmighty@hotmail.co.uk";
$subject = "Contact Us";
$name_field = $_REQUEST['name'] ;
$email_field = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email_field";
$body = "Name: $name\n E-Mail: $email\n Message:\n $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?>



</body>
</html>

 

When i use that code i can get the message section to send to me perfectly but the name_field and email_field dont send.  Was wondering if anything stands out which i have not done right?

 

Thanks again for help so far.  Appreciate it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.