Jump to content

Mail Function - Should I/How do I add Form fields to $message?


allotrope

Recommended Posts

Hello there,

 

I'm new to PHP from this morning & it's all very exciting!

 

I was wondering if someone might be able to help me: I have created a form & want to send the results via php to my email address.

 

I've used the mail function & I think I have to define the $message as equal to the all the fields of my form (i.e. name, otherformtextinfield etc.. except email).

 

Can anyone give me advice on how to do this?

 

I had hope that when i had ...... , $message, ......)  i could add my form fields to that i.e.  ........, $message $name $otherformtextinfield, ......

 

but that didn't work! Probably

 

Thanks

 

Allotrope.

Link to comment
Share on other sites

There are many ways of doing this. Perhaps the easiest is to use the print_r() to dump the values of the $_POST array into your message. It's not really formatted nicely, but it is quick:

<?php
$message = 'The following information was entered:' . "\n";
$message .= print_r($_POST,true);
mail($to,$subject,$message);
?>

 

Ken

Link to comment
Share on other sites

 

Thanks Ken I appreciate your response. I tried what you said...

 


<?php

$message = 'The following information was entered:' . "\n";
$message .= print_r($_POST,true);


  mail( "myemail@something.com", "Newsletter Request", $message, "From: $Email" );
  header( "Location: http://www.website.co.uk" );


?>

 

However I'm not sure then how to create an array?

 

I had tried this

 

<?php

$message = $_REQUEST['Name'], $_REQUEST['Salon'] ;

  mail( "myemail@something.com", "Newsletter Request", $message, "From: $Email" );
  header( "Location: http://www.website.co.uk" );
?>

Which I know is wrong!

Link to comment
Share on other sites

I started learning PHP this morning to add a join newsletter form to a website this morning. So I learn't how to do it in part from here .. h**p://www.thesitewizard.com/archive/feedbackphp.shtml (to explain why I put the website header).

 

I don't know how to use the $_POST function so I can't quite piece it all together.

 

I will post my form if you have the time to look at it..

 


<div id="form">
<script language="JavaScript" src="form.js" type="text/javascript"></script>
  <form id="Newsletter" name="form1" method="post" action="sendflsmailb.php">
    
    <input 	type="text" id="inputname" value="Name" name="Name" 
						onfocus="inputName(); style.color='#000'; style.borderColor='#000';" 
						onblur="inputNameOff(); style.borderColor='';" /><br />

    <input 	type="text" id="inputemail" value="Email" name="Email" 
						onfocus="inputEmail(); style.color='#000'; style.borderColor='#000';" 
						onblur="inputEmailOff(); style.borderColor='';" /><br />

    <input 	type="text" id="inputsalon" value="Salon" name="Salon" 
						onfocus="inputSalon(); style.color='#000'; style.borderColor='#000';" 
						onblur="inputSalonOff(); style.borderColor='';" /><br />

    <input name="Send" type="submit" value="Join Our Newsletter" />
    
    </form>
</div>

 

Could you recommend anywhere to learn PHP online?

 

Thank you!

 

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.