Jump to content

HTML form to Mail Function


mulderthe23rd

Recommended Posts

I'll be honest: I'm a senior in an ITP program and I don't know much about PHP. (Hell, the shop instructor knows less than I do!) But I decided to try it on a website I need to make. And since I'm posting here, I think you can guess how well it went. I can get the email to send, but it doesn't take information - specifically, from a drop-down menu.

 

So, let's see if we can go over the code and find out the right's and wrongs. Please? (And yes, it is a Harry Potter website. It had to be themed. :P)

 

HTML Form:

<form method="post" action="../askmarauders.php">
Your Name: <input type="text" name="yourname"></textarea>
<br />
Email: <input name="email" type="text" />
<br />
For: 
    
<select name="for">
<option value="Remus">Remus Lupin</option>
<option value="Peter">Peter Pettigrew</option>
<option value="Sirius">Sirius Black</option>
<option value="James">James Potter</option>
<option value="Severus">Severus Snape</option>
<option value="Lily">Lily Evans</option>
<option value="Group">A group (speficy in message)</option>
<option value="Anyone">Anyone can answer</option>
<option value="all">My question is for everyone!</option>
</select>
<br />
Message:
<br />
<textarea name="txt" rows="15" cols="40">
</textarea>
<br />
<input type="submit" name="submit" value="Submit"/>
</form>

PHP Code:

<?php
  
$to = "moony_is_mine@hotmail.com";
$email = $_REQUEST['email'];
$subject = "Ask the Marauders";
$for = $_REQUEST['for']
$txt = $_REQUEST['txt'];
$headers = "From: $email" . "For: $for" . "\r\n" .
"Location: thankyou.htm";

mail($to,$subject,$txt,$headers);
  
  
?>

Quote clearly, I'm a PHP loser n00b very bad beginner. Can anyone help me figure this out?

Link to comment
Share on other sites

You have the value of the $_REQUEST['for'] select box variable going into the email headers. Should it not be in the body of the email instead? It seems you also are confusing email headers with the PHP header() function. What exactly is the result you are trying to get, from start to finish?

Link to comment
Share on other sites

mail header, or http header, or ftp header, is those thing the server sending to each other, telling each other, what kind of information they both receiving

 

like,

who it is from, what type of text encoding, how the connection be handled after everything are done

etc

these header wont be seen in header, and human eyes

 

just the server will see it, and process it by the meaning of the sender

 

like http header

http 1.1 200 OK

content-type: text/html

connection: close

 

the above 3 lines are the most common type of header when u use browser (100% of browser will send this out)

do u see these 3 lines?

NO

 

so, the header in mail is same, it wont be seen by human eye, except the following

From:

(maybe more)

 

 

according to this link,

the For header isnt used like the way u do

http://www.avolio.com/columns/E-mailheaders.html

Link to comment
Share on other sites

the below should process your form, just edit your askmarauders.php to accommodate the following code

 


<?php
//  recipient
$to  = 'YourEmail@example.com' ;

// subject
$subject = 'Some Subject';

// variables
$name = $_POST['yourname'];
$email = $_POST['email'];
$for = $_POST['for'];
$txt = $_POST['txt'];


// message
$message = "
<b>Name: </b>$name \n\n
<b>Email: </b>$email \n\n
<b>For: </b>$for \n\n
<b>Txt: </b>$txt \n\n
";

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= "To: YourName <YourEmail@example.com>" . "\r\n";
$headers .= "From: $name <$email>" . "\r\n";


// Mail it
mail($to, $subject, $message, $headers);
?>

Link to comment
Share on other sites

the below should process your form, just edit your askmarauders.php to accommodate the following code

 


<?php
//  recipient
$to  = 'YourEmail@example.com' ;

// subject
$subject = 'Some Subject';

// variables
$name = $_POST['yourname'];
$email = $_POST['email'];
$for = $_POST['for'];
$txt = $_POST['txt'];


// message
$message = "
<b>Name: </b>$name \n\n
<b>Email: </b>$email \n\n
<b>For: </b>$for \n\n
<b>Txt: </b>$txt \n\n
";

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= "To: YourName <YourEmail@example.com>" . "\r\n";
$headers .= "From: $name <$email>" . "\r\n";


// Mail it
mail($to, $subject, $message, $headers);
?>

 

This is easy enough to follow. But for some reason, it won't take anything from txt. All of the other information works - but the email I receive has nothing in it aside from the name, the email, etc. No actual "message" appears.

 

Oh, and thanks to everyone else who replied :D A great help.

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.