Simple Question - Make "From" a Value From Form

I simply need to make the email that arrives show that it is from the person filling out the form online. The current line of code makes the email appear as though it is from myself and is causing it to go straight to my junkmail.

mail($emailadd, $subject, $text, 'From: '.$emailadd.'');

What should ‘From: ‘_____’’ be? I would like it to be the result of the text field named “Name” in my form.

Also, for the subject line, can I make is say "Inquiry From “Company” " and insert the result from the text field “Company” into the subject line.

$subject = 'Inquiry from '_______''; 

I’m thinking these are pretty easy things…but if someone can help me out, that’d be great!

Why not just add an email field to your form? This way, you can have user name and email set as “From:”
But you will also need to validate email address entered in the form, so that your form is not get abused by spammers. For example, if you added field named Email to your form, the validation code will be:
[php]if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,4})$", $_POST[“Email”])){
die(‘Email Address is not valid! Please enter your valid Email Address.’);
}
else{
mail($emailadd, $subject, $text, ‘From: ‘.$_POST[‘Name’].’ <’.$_POST[‘Email’].’>’);
}[/php]

Also, it make sense to sanitize $_POST[‘Name’] (i.e. remove any \n or \r chars)

Also, I do have the both the name and email fields in my form, as well as verification requiring a valid email address.

I tested the code and it worked perfect!!! Yay!

Also, for the subject line, I figured it out following the logic provided in your response. The code I ended up using was

$subject = 'Inquiry from '.$_POST['Company'].' '; 

Thanks for your quick help with this.

Sponsor our Newsletter | Privacy Policy | Terms of Service