Jump to content

PHP Form Help


makeITfunctional

Recommended Posts

Hi, PHP Freaks,

 

I have two questions for you:

 

Based on the code below, I am trying to get the form, when it is emailed to me, to be from the email address in field_5.  I know it has something to do with headers, but what would that code look like? 

 

Second, if there is a captcha error, the PHP code takes you to a blank page to display the message "Invalid Captcha  Please press the back button on your browser and try again".  Is there a way to have that code appear in a dialog box on the same page as the form?  If so, what would that code look like? 

 

Thanks so much!  Here is the code below:

 

 


<?php

session_start();
if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) { 
// File upload handling
if($_FILES['field_9']['name']!=''){
$field_9_filename = "file_9_".date("sihdmY").substr($_FILES['field_9']['name'],strlen($_FILES['field_9']['name'])-4);
if(!move_uploaded_file($_FILES['field_9']['tmp_name'], "./upload/".$field_9_filename)){
die("File " .  $_FILES['field_9']['name'] . " was not uploaded.");
}
}

mail("[email protected]","Form submission email","Form data

First Name: " . $_POST['field_1'] . " 
Last Name: " . $_POST['field_2'] . " 
Organization: " . $_POST['field_3'] . " 
Website: " . $_POST['field_4'] . " 
Email: " . $_POST['field_5'] . " 
Phone: " . $_POST['field_7'] . " 
Description: " . $_POST['field_8'] . " 
File: ".$where_form_is."upload/".$field_9_filename." (original file name: " . $_FILES['field_9']['name'] . ")

");

include("form_completed.html");
}
else {
echo "Invalid Captcha  Please press the back button on your browser and try again";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/189566-php-form-help/
Share on other sites

Hello have a look at http://php.net/manual/en/function.mail.php, your problem is that mail takes the arguments 'to', 'subject', 'message' and then optional headers. You want to put the from/reply to address in the optional headers.

 

In the optional header the string "From: [email protected]" then this is the address that the message will appear to have come from.

 

As to you problem with pop up boxes instead of different pages, I am new to this so I'm probably wrong, but I think your only way is with ajax.

Link to comment
https://forums.phpfreaks.com/topic/189566-php-form-help/#findComment-1000600
Share on other sites

Thanks, pernest for responding. 

 

As for the optional headers of:

 

$to      = '[email protected]';

$subject = 'the subject';

$message = 'hello';

$headers = 'From: [email protected]' . "\r\n" .

    'Reply-To: [email protected]' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

 

mail($to, $subject, $message, $headers);

 

How do I make them dynamic based on the code from my original post?

Link to comment
https://forums.phpfreaks.com/topic/189566-php-form-help/#findComment-1000601
Share on other sites

Well, the address you want as the reply to I guess is $_POST['field_5']. So just put the arguments together like so:

 

$to = "[email protected]";

$subject ="the subject of your message";

$body = "the body of your message";

$headers = "From: ".$_POST['field_5'];

 

then fire of the mail with

 

mail($to,$from,$body,$headers);

 

You might want to check that the email address that your used have submitted to you is a valid one, a proper function for this can be found here http://www.linuxjournal.com/article/9585, there are much simpler ones, but they disallow some uncommon but valid addresses.

Link to comment
https://forums.phpfreaks.com/topic/189566-php-form-help/#findComment-1000603
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.