Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Added new form input data but not received in email. how to solve ?

Status
Not open for further replies.

MoonCoffee

Programmer
Sep 17, 2012
4
Hi,

I'm having problem added new input data in html entry form but was not received in email, what is going wrong?

Created another input "Company" (no validation needed) in form entry. Please show me how to edit from original contact.php in order to receive the company input data from email. Being trying long hours but still can not figure out, please help.

Thank you very much.

below is the original contact.php :-

$values = array ('name','email','message');
$required = array('name','email','message');

$your_email = "name@gmail.com";
$email_subject = "New Message";
$email_content = "new message:\n";

//for( $i = 0 ; $i < count( $values ) ; ++$i ) {
// for( $c = 0 ; $c < count( $required ) ; ++$c ) {
// if( $values[$i]==$required[$c] ) {
// echo $required[$x];
// if( empty($_POST[$values[$i]]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
// }
// }
// $email_content .= $values[$i].': '.$_POST[$values[$i]]."\n";
//}

foreach($values as $value){
if(in_array($value,$required)){
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
$email_content .= $value.': '.$_POST[$value]."\n";
}
$_POST['message'];
}


if(mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>
 
Hi

MoonCoffee said:
Being trying long hours but still can not figure out,
What exactly you tried ? I suppose not this one :
Code:
[navy]$values[/navy] [teal]=[/teal] [b]array[/b] [teal]([/teal][green][i]'name'[/i][/green][teal],[/teal][green][i]'email'[/i][/green][teal],[/teal][green][i]'message'[/i][/green][highlight][teal],[/teal][green][i]'Company'[/i][/green][/highlight][teal]);[/teal]
( Note that you will have to add the [tt]input[/tt]'s [tt]name[/tt] as used in the [tt]form[/tt], with the same letter case. )

Feherke.
[link feherke.github.com/][/url]
 
tq for ur reply.

company defined in form and added in php like ur way but not working, not display in email body.

from above php i received email as below:

new message:
name: Moon
email: moooon@gmail.com
message: please quote


how can i get company display after or before message like :

new message:
name: Moon
email: moooon@gmail.com
company : abc company
message: please quote


above problem couldn't be solved, been thinking another solution to get data display in email Subject :-
$email_subject = "From : ".$_POST['company'].$_POST['phone'].$_POST['industry'];

will get email subject like below:

[highlight #729FCF]From : ABC Company0122222222Chemical[/highlight]

my question is how can i get spacing in between like :
[highlight #729FCF]From : ABC Company 0122222222 Chemical[/highlight]

Please help. Thank you.



 
Hi

I think I found the logic error. ( Is hard to detect anything in such mess. Please choose an Indent style and use it consistently. ) Only required fields were added to the message. Change the loop into this :
Code:
[b]foreach[/b] [teal]([/teal][navy]$values[/navy] [b]as[/b] [navy]$value[/navy][teal])[/teal] [teal]{[/teal]
  [b]if[/b] [teal]([/teal][COLOR=darkgoldenrod]in_array[/color][teal]([/teal][navy]$value[/navy][teal],[/teal][navy]$required[/navy][teal]))[/teal] [teal]{[/teal]
    [b]if[/b] [teal]([/teal][b]empty[/b][teal]([/teal][navy]$_POST[/navy][$value][teal]))[/teal] [teal]{[/teal] [b]echo[/b] [green][i]'PLEASE FILL IN REQUIRED FIELDS'[/i][/green][teal];[/teal] [b]exit[/b][teal];[/teal] [teal]}[/teal]
  [teal]}[/teal]
  [navy]$email_content[/navy] [teal].=[/teal] [navy]$value[/navy][teal].[/teal][green][i]': '[/i][/green][teal].[/teal][navy]$_POST[/navy][$value][teal].[/teal][green][i]"\n"[/i][/green][teal];[/teal]
[teal]}[/teal]


Feherke.
[link feherke.github.com/][/url]
 
Hi Feherke

above code tested still listed required fields only. not working.

[highlight #FCE94F]anyway to list ".$_POST['company'] before the looping end ?[/highlight]

or how to add spacing in between

[highlight #EDD400]$email_subject = "From : ".$_POST['company'].$_POST['phone'].$_POST['industry'];[/highlight]
 
figured out the solution :-

$email_subject = "From : ".$_POST['company'][highlight #FCE94F]." "[/highlight].$_POST['phone'][highlight #FCE94F]." "[/highlight].$_POST['industry'];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top