By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,637 Members | 2,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,637 IT Pros & Developers. It's quick & easy.

PHP Code Pop-up...

P: 7
I am currently working on a form that would have multiple fields plus an upload file spot. I cannot add the code for the upload file. Also, after clicking submit the form should send an email to the specified email address and currently those emails are not being recieved. All that happens is the php code box ocomes up and lets the user know that the form has been submitted and doesn't re-direct to the thank you page..Please help

Here is my php formmail code...

<?
///////////////////////////////////////////////////////////////////
// PERFECT //
///////////////////////////////////////////////////////////////////

// Configuration Settings
$SendFrom = "sales@lantekonline.com";
$SendTo = "ayob@lantekonline.com";
$SubjectLine = "Feedback Submission";
$ThanksURL = "http://www.lantekonline.com/html/asset_thankyou.htm"; //confirmation page
$Divider = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value)
$MsgBody .= "$Field: $Value\n";
$MsgBody .= "$Divider\n" . $_SERVER["HTTP_USER_AGENT"] . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe

// Send E-Mail and Direct Browser to Confirmation Page
mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom");
header("Location: $ThanksURL");
?>
Jan 29 '07 #1
Share this Question
Share on Google+
5 Replies


Motoma
Expert 2.5K+
P: 3,235
I am currently working on a form that would have multiple fields plus an upload file spot. I cannot add the code for the upload file. Also, after clicking submit the form should send an email to the specified email address and currently those emails are not being recieved. All that happens is the php code box ocomes up and lets the user know that the form has been submitted and doesn't re-direct to the thank you page..Please help

Here is my php formmail code...

<?
///////////////////////////////////////////////////////////////////
// PERFECT //
///////////////////////////////////////////////////////////////////

// Configuration Settings
$SendFrom = "sales@lantekonline.com";
$SendTo = "ayob@lantekonline.com";
$SubjectLine = "Feedback Submission";
$ThanksURL = "http://www.lantekonline.com/html/asset_thankyou.htm"; //confirmation page
$Divider = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value)
$MsgBody .= "$Field: $Value\n";
$MsgBody .= "$Divider\n" . $_SERVER["HTTP_USER_AGENT"] . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe

// Send E-Mail and Direct Browser to Confirmation Page
mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom");
header("Location: $ThanksURL");
?>
Files are accessed via the $_FILES variable (much like $_POST and $_GET).
In order to send mail, you will need to have your server configured to do so.
A header("Location:") call will not work if anything gets printed or echoed to the web-browser.
Jan 29 '07 #2

P: 7
Files are accessed via the $_FILES variable (much like $_POST and $_GET).
In order to send mail, you will need to have your server configured to do so.
A header("Location:") call will not work if anything gets printed or echoed to the web-browser.


How can I do that? Here is the form I am trying to work with, if it helps
[HTML]<form action="formmail.php" method="POST">
<input type="hidden" name="recipient" value="ayob@lantekonline.com">
<input type="hidden" name="subject" value="Asset Investment Form">
<input type="hidden" name="thanks" value="http://www.lantekonline.com/html/asset_thankyou.htm" />
<input type="hidden" name="required" value="email,realname">
<input type="hidden" name="alias" value="email=E-mail Address,realname=Name">
<input type="hidden" name="alias_method" value="email">
<input type="hidden" name="mail_newline" value="2">
<input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR">
<input type="hidden" name="print_blank_fields" value="true">
<input type="hidden" name="gmt_offset" value="-5">

<table align="center" width="535" cellspacing="2" cellpadding="5" border="1" height="254">
<tr>
<td width="133" height="2" align="right"><font color="6e2f32" face="Alps">Name:</font></td>
<td width="370" height="2" align="left"><input type="Text" name="realname" align="LEFT" size="35" maxlength="100">
</td>
</tr>
<tr>
<td align="right"><font color="6e2f32" face="Alps">Email: </font></td>
<td align="left"><input type="Text" name="email" align="RIGHT" size="35" maxlength="100">
</td>
</tr>
<tr>
<td align="right"><font color="6e2f32" face="Alps">Title: </font></td>
<td align="left"><input type="Text" name="title" align="RIGHT" size="35" maxlength="100">
</td>
</tr>
<tr>
<td align="right" height="4"><font color="6e2f32" face="Alps">Company:</font></td>
<td align="left" height="4"><input type="Text" name="company" size="35" maxlength="100" >
</td>
</tr>
<tr>
<td align="right" height="4"><font color="6e2f32" face="Alps">Address:</font></td>
<td align="left" height="4"><input type="Text" name="Address" align="LEFT" size="35" maxlength="100">
</td>
</tr>
<tr>
<td align="right" height="4">&nbsp;</td>
<td align="left" height="4"><input type="Text" name="Address2" align="LEFT" size="35" maxlength="100">
</td>
</tr>
<tr>
<td align="right"><font color="6e2f32" face="Alps">City, State Zip: </font></td>
<td align="left"><input type="Text" name="city" align="LEFT" size="25" maxlength="75">
&nbsp;&nbsp;&nbsp;
<input type="Text" name="State" align="LEFT" size="2" maxlength="2">
&nbsp;&nbsp;&nbsp;
<input type="Text" name="Zip" align="LEFT" size="5" maxlength="10">
</td>
</tr>
<tr>
<td align="right"><font color="6e2f32" face="Alps">Phone: </font></td>
<td align="left"><input type="Text" name="phone" align="LEFT" size="15" maxlength="15">
&nbsp;&nbsp;&nbsp; </td>
</tr>
<tr>
<td align="right"><font color="6e2f32" face="Alps">Fax: </font></td>
<td align="left"><input type="Text" name="fax" align="LEFT" size="15" maxlength="15">
&nbsp;&nbsp;&nbsp; </td>
</tr>
</table>
<table width="535" border="1" align="center" cellpadding="5" cellspacing="2">
<tr>
<td colspan="2"><font color="6e2f32" face="Alps">Please provide an approximate asset inventory: </font></td>
</tr>
<tr>
<td width="287" height="202"><p><font color="6e2f32" face="Alps"><br>
Manufacturer(s), Model(s), Quantity, Specifications(If possible): <br>
</font></p>
<p><font color="6e2f32" face="Alps">Do you currently have a PC Refresh Plan?(If yes, how many years?)<br>
<br>
If you have a pre-existing file containing this information, please upload it here</font></p></td>
<td width="242"><p>
<textarea name="manufacturer_model_Quantity_spec"></textarea>
</p>
<p> <font color="6e2f32" face="Alps">
<input name="yes_no" type="Text" size="4" maxlength="4">
<input name="Years" type="Text" id="Years" size="10" maxlength="10">
</font><br>

<br>
</p>
<p> <input type="file" name="upload">
</p></td>
</tr>
</table>
<font color="#0000A0"><BR>
</font>
<DIV align="center">
<INPUT name="submit" type="submit" value="Submit">
</DIV>
</form>[/HTML]
Jan 29 '07 #3

Motoma
Expert 2.5K+
P: 3,235
This link explains file uploads in PHP.
Jan 29 '07 #4

P: 7
So if i understand that correctly, i need to use 2 form tags for this script?
Jan 29 '07 #5

Motoma
Expert 2.5K+
P: 3,235
So if i understand that correctly, i need to use 2 form tags for this script?
No, you will need to set your form's ENCTYPE properly, and access your file through the $_FILES variable.
Jan 29 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.