From form sender's email included

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
anitta
Forum Newbie
Posts: 5
Joined: Wed Jan 21, 2009 2:20 pm

From form sender's email included

Post by anitta »

I have the following php running a form, but it will not, send the form poster's email address in the From section:

HELP - I have tried writing this six ways to sunday - and I'm a bit of a PHP novice :banghead:

Code: Select all

 
<?php
 
$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));
 
session_start();
if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) { 
// Checkbox handling
$field_8_opts = $_POST['field_8'][0].",". $_POST['field_8'][1].",". $_POST['field_8'][2].",". $_POST['field_8'][3].",". $_POST['field_8'][4].",". $_POST['field_8'][5].",". $_POST['field_8'][6].",". $_POST['field_8'][7].",". $_POST['field_8'][8];
 
// Checkbox handling
$field_11_opts = $_POST['field_11'][0].",". $_POST['field_11'][1].",". $_POST['field_11'][2].",". $_POST['field_11'][3].",". $_POST['field_11'][4].",". $_POST['field_11'][5];
 
$name = $HTTP_POST_VARS['field_18'];
$email = $HTTP_POST_VARS['email'];
 
$name = stripslashes($name);
$email = stripslashes($email);
 
$to = 'my@myemailaddress.com';
$subject = 'My Form Submission';
$message = "
 
First Name: " . $_POST['field_17'] . " 
Last Name: " . $_POST['field_18'] . " 
 
Best Number to Reach You: " . $_POST['field_19'] . "
 
Street Address: " . $_POST['field_20'] . " 
City: " . $_POST['field_21'] . " 
Postal Code: " . $_POST['field_22'] . " 
 
email: " . $_POST['email'] . " 
_______________________________________________
Style of Your Home: " . $_POST['field_1'] . " 
Type of Home: " . $_POST['field_2'] . " 
Age of Home: " . $_POST['field_3'] . "  
# of Bedrooms: " . $_POST['field_4'] . "  
# of Bathrooms: " . $_POST['field_5'] . "  
Garage: " . $_POST['field_6'] . "  
Square Footage: " . $_POST['field_7'] . "  
Other Features: $field_8_opts   
Other Noteable Features: " . $_POST['field_9'] . "   
Where is Your Home Located?: " . $_POST['field_10'] . "  
Area Influences: $field_11_opts   
Other Area Influences: " . $_POST['field_12'] . " 
 
_________________________________________________________
In Your Opinion, What is The Value of Your Home?: " . $_POST['field_13'] . " 
 
Are You Working With a Realtor?: " . $_POST['field_14'] . " 
 
Do You Need to Sell In Order to Purchase?: " . $_POST['field_15'] . " 
 
What is Your Timeframe to move?: " . $_POST['field_16'];
 
$header_info = "From: ".$name." <".$email.">";
 
mail($to, $subject, $message, $header_info);
 
include("confirm.html");
}
else {
echo "Invalid Captcha String.";
}
 
?>
 
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: From form sender's email included

Post by Burrito »

Please use PHP tags when posting code in the forums.

try adding a \r\n at the end of the line in your header string.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: From form sender's email included

Post by Burrito »

also if you're on windows, there is a known bug about the from header not always working. I think the workaround is reset something in php.ini using ini_set().

something like this:

Code: Select all

 
ini_set('sendmail_from', 'someone@whatever.com');
 
you'll have to check on that to be sure though on the bugs site....
anitta
Forum Newbie
Posts: 5
Joined: Wed Jan 21, 2009 2:20 pm

Re: From form sender's email included

Post by anitta »

Thanks for the reply - sorry about the tags - bad newbie :oops:

I tried the \r\n but that did not work and as for the ini thing - man that is too much for me!

I come from design world mostly - and write the most basic of php stuff.

My web host told me that he installed a new security sytem due to some hack abouts running with some of his hosted php files.

Do you think that could have anything to do with it? I am soooo at a loss. Everything else comes through except the form fillers email, and I need to be aboe to autorespond to them.

Do you know of anyway else I could possibly write this or where I can get it written - I feel I am getting beyond my element.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: From form sender's email included

Post by Burrito »

what platform is the server? If it's windows...look at what I suggested with the ini_set() thing.

it's possible it's not working because the mail server isn't allowing the headers to go through. There are alternatives to the mail() function, the best of which is SwiftMailer which would provide a lot more flexibility in terms of mail composition and routing.
anitta
Forum Newbie
Posts: 5
Joined: Wed Jan 21, 2009 2:20 pm

Re: From form sender's email included

Post by anitta »

Thanks again - I will look into both a little further - but as of now I have been in this chair in my studio for 13 hours and I gotta say I'm dusted.

I will check both out in the am.

Thanks for your input.
anitta
Forum Newbie
Posts: 5
Joined: Wed Jan 21, 2009 2:20 pm

Re: From form sender's email included

Post by anitta »

After trying a lot of different things - I had a chat with the guy who runs my server - it appears he installed a new ModSecurity on the server.

Does anyone know anything about ModSecurity and what an rx error message means?

It seems like this might be the issue
anitta
Forum Newbie
Posts: 5
Joined: Wed Jan 21, 2009 2:20 pm

Re: From form sender's email included

Post by anitta »

How do I make this script run - apparently my host has changed to php5.1.6 with globals off and now I am not sure what I have to change.

Can anyonw tell me?
Post Reply