Jump to content

Archived

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

kaspm

Email Form Fields

Recommended Posts

Hi I have a form I would like to have emailed to me. Here is the code I have on the page of the form. It sends the email, but it is just blank. Can you please help?

[code]<?php
$to = 'myemail@email.com';
$subject = 'Subject';
$name = $_POST['Field1'] . "\r\n" . $_POST['Field2'] . "\r\n" . $_POST['Field3'] . "\r\n" . $_POST['Field4'] . "\r\n" . $_POST['Field5'] . "\r\n" . $_POST['Field6'] . "\r\n" . $_POST['Field7'] . "\r\n" . $_POST['Field8'] . "\r\n" . $_POST['Field10'] . "\r\n" . $_POST['Field11'];
$message = $name;
$headers = 'From: email@email.com' . "\r\n";

mail($to, $subject, $message, $headers);
?>[/code]

Share this post


Link to post
Share on other sites
I guess the first thing I'd do (if you haven't already) is print_r($_POST); to be sure that you actually have any data to send. Then take it from there...

Share this post


Link to post
Share on other sites
There is data to send. I have this same code on multipage form and it works fine

Share this post


Link to post
Share on other sites
Ok, I just always check that kind of stuff first. I don't see anything obviously wrong with your code. Are you able to turn on display_errors in the php.ini if it's not already? Can you access the httpd error log? Sometimes those provide a little help...

Also, I don't think you need a "\r\n" after the From header, since there are no additional headers being sent.

Share this post


Link to post
Share on other sites
would it be a problem if i have a file upload on the same page

Share this post


Link to post
Share on other sites
If you can post you HTML form, it'll be easier to debug.

Share this post


Link to post
Share on other sites
[code]<form name="BillingForm" method="POST" enctype="multipart/form-data" action="<?php echo $uploadHandler ?>">
&nbsp;<table cellspacing="0" cellpadding="4" height="470" border="1" bordercolor="#000000" style="border-collapse: collapse" width="665">
    <tr>
      <td width="105" height="32"></td>
      <td width="124" height="32"></td>
      <td width="374" height="32">&nbsp;</td>
    </tr>
    <tr>
      <td rowspan="9" width="105" height="289"></td>
      <td width="124" height="22">Name</td>
      <td width="374" height="22"><input type="text" name="Field1" size="50"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="36">Company Name</td>
      <td width="374" height="36"><input type="text" name="Field2" size="50"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="22">Address1</td>
      <td width="374" height="22"><input type="text" name="Field3" size="50"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="22">Address2</td>
      <td width="374" height="22"><input type="text" name="Field4" size="50"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="44">City/State/Zip</td>
      <td width="374" height="44"><input type="text" name="Field5" size="35"
      value=""> <select name="Field6" size="1">
<option>AL<option>AK<option>AS<option>AZ<option>AR<option>CA<option>CO<option>CT<option>DE<option>DC<option>FM<option>FL<option>GA<option>GU<option>HI<option>ID<option>IL<option>IN<option>IA<option>KS<option>KY<option>LA<option>ME<option>MH<option>MD<option>MA<option>MI<option>MN<option>MS<option>MO<option>MT<option>NE<option>NV<option>NH<option>NJ<option>NM<option>NY<option>NC<option>ND<option>MP<option>OH<option>OK<option>OR<option>PW<option>PA<option>PR<option>RI<option>SC<option>SD<option>TN<option>TX<option>UT<option>VT<option>VI<option>VA<option>WA<option>WV<option>WI<option>WY      </select> <input type="text" name="Field7" size="10"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="36">Home Phone</td>
      <td width="374" height="36"><input type="text" name="Field8" size="15"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="36">Office Phone</td>
      <td width="374" height="36"><input type="text" name="Field9" size="15"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="23">E-Mail</td>
      <td width="374" height="23"><input type="text" name="Field10" size="50"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="23">File Upload</td><td width="425"><input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"><input type="file" id="file1" name="file[]" size="50"></td>
    </tr>
    <tr>
      <td rowspan="3" width="105" valign="top" height="45">&nbsp;</td>
    </tr>
    <tr>
      <td width="124" height="1"></td>
      <td width="374" height="1"></td>
      <td height="1" width="61">
      <input type="submit" value="Submit" name="submit" onClick="validateForm();"></td>
    </tr>
  </table>
</form>[/code]

Share this post


Link to post
Share on other sites
I tried your script as is, and it worked fine form me!!!

Try to make the script send the mail then upload the file?

Share this post


Link to post
Share on other sites
Is there a way to do that with out making it a seperate page

Share this post


Link to post
Share on other sites
I am not sure how the $uploadHandler is set up, but you can set the mail function to be first, than go one with uploading the file.

Share this post


Link to post
Share on other sites
This is the upload handler
[code]<?php

// filename: upload.processor.php

// first let's set some variables

// make a note of the current working directory, relative to root.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

// make a note of the directory that will recieve the uploaded files
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . '/uploaded_files';

// make a note of the location of the upload form in case we need it
$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'multiple.upload.form.php';

// make a note of the location of the success page
$uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'multiple.upload.success.php';

// name of the fieldname used for the file in the HTML form
$fieldname = 'file';

//echo'<pre>';print_r($_FILES);exit;



// Now let's deal with the uploaded files

// possible PHP upload errors
$errors = array(1 => 'php.ini max file size exceeded',
                2 => 'html form max file size exceeded',
                3 => 'file upload was only partial',
                4 => 'no file was attached');

// check the upload form was actually submitted else print form
isset($_POST['submit'])
    or error('the upload form is neaded', $uploadForm);
    
// check if any files were uploaded and if
// so store the active $_FILES array keys
$active_keys = array();
foreach($_FILES[$fieldname]['name'] as $key => $filename)
{
    if(!empty($filename))
    {
        $active_keys[] = $key;
    }
}

// check at least one file was uploaded
count($active_keys)
    or error('No files were uploaded', $uploadForm);
        
// check for standard uploading errors
foreach($active_keys as $key)
{
    ($_FILES[$fieldname]['error'][$key] == 0)
        or error($_FILES[$fieldname]['tmp_name'][$key].': '.$errors[$_FILES[$fieldname]['error'][$key]], $uploadForm);
}
    
// check that the file we are working on really was an HTTP upload
foreach($active_keys as $key)
{
    @is_uploaded_file($_FILES[$fieldname]['tmp_name'][$key])
        or error($_FILES[$fieldname]['tmp_name'][$key].' not an HTTP upload', $uploadForm);
}
    
// validation... since this is an image upload script we
// should run a check to make sure the upload is an image
foreach($active_keys as $key)
{
    @getimagesize($_FILES[$fieldname]['tmp_name'][$key])
        or error($_FILES[$fieldname]['tmp_name'][$key].' not an image', $uploadForm);
}
    
// make a unique filename for the uploaded file and check it is
// not taken... if it is keep trying until we find a vacant one
foreach($active_keys as $key)
{
    $now = time();
    while(file_exists($uploadFilename[$key] = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'][$key]))
    {
        $now++;
    }
}

// now let's move the file to its final and allocate it with the new filename
foreach($active_keys as $key)
{
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'][$key], $uploadFilename[$key])
        or error('receiving directory insuffiecient permission', $uploadForm);
}
    
// If you got this far, everything has worked and the file has been successfully saved.
// We are now going to redirect the client to the success page.
header('Location: ' . $uploadSuccess);

// make an error handler which will be used if the upload fails
function error($error, $location, $seconds = 5)
{
    header("Refresh: $seconds; URL=\"$location\"");
    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
    '<html lang="en">'."\n".
    '    <head>'."\n".
    '        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
    '        <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
    '    <title>Upload error</title>'."\n\n".
    '    </head>'."\n\n".
    '    <body>'."\n\n".
    '    <div id="Upload">'."\n\n".
    '        <h1>Upload failure</h1>'."\n\n".
    '        <p>An error has occured: '."\n\n".
    '        <span class="red">' . $error . '...</span>'."\n\n".
    '         The upload form is reloading</p>'."\n\n".
    '     </div>'."\n\n".
    '</html>';
    exit;
} // end error handler

?>[/code]

Share this post


Link to post
Share on other sites
I don't see this anywhere in the file?
[code]
<?php
$to = 'myemail@email.com';
$subject = 'Subject';
$name = $_POST['Field1'] . "\r\n" . $_POST['Field2'] . "\r\n" . $_POST['Field3'] . "\r\n" . $_POST['Field4'] . "\r\n" . $_POST['Field5'] . "\r\n" . $_POST['Field6'] . "\r\n" . $_POST['Field7'] . "\r\n" . $_POST['Field8'] . "\r\n" . $_POST['Field10'] . "\r\n" . $_POST['Field11'];
$message = $name;
$headers = 'From: email@email.com' . "\r\n";

mail($to, $subject, $message, $headers);
?>
[/code]

Share this post


Link to post
Share on other sites
That part of the code is on my page with the form on it. This is the code for my page with the form.

[code]<?php
$to = 'sold@photocardsandcalendars.com';
$subject = 'Calendar Sold';
$name = $_POST['BillingName'] . "\r\n" . $_POST['BillingCompany'] . "\r\n" . $_POST['BillingAddr1'] . "\r\n" . $_POST['BillingAddr2'] . "\r\n" . $_POST['BillingCity'] . "\r\n" . $_POST['BillingState'] . "\r\n" . $_POST['BillingZip'] . "\r\n" . $_POST['BillingPhone1'] . "\r\n" . $_POST['BillingPhone2'] . "\r\n" . $_POST['BillingEmail'];
$message = $name;
$headers = 'From: sales@photocardsandcalendars.com' . "\r\n";

mail($to, $subject, $message, $headers);
?>
<?php

// filename: upload.form.php

// first let's set some variables

// make a note of the current working directory relative to root.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

// make a note of the location of the upload handler
$uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'multiple.upload.processor.php';

// set a max file size for the html upload form
$max_file_size = 10000000; // size in bytes

// now echo the html page
?>
<html>

<head></head>
<body>
<form name="BillingForm" method="POST" enctype="multipart/form-data" action="<?php echo $uploadHandler ?>">
&nbsp;<table cellspacing="0" cellpadding="4" height="470" border="1" bordercolor="#000000" style="border-collapse: collapse" width="665">
    <tr>
      <td width="105" height="32"></td>
      <td width="124" height="32"></td>
      <td width="374" height="32">&nbsp;</td>
    </tr>
    <tr>
      <td rowspan="9" width="105" height="289"></td>
      <td width="124" height="22">Name</td>
      <td width="374" height="22"><input type="text" name="Field1" size="50"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="36">Company Name</td>
      <td width="374" height="36"><input type="text" name="Field2" size="50"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="22">Address1</td>
      <td width="374" height="22"><input type="text" name="Field3" size="50"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="22">Address2</td>
      <td width="374" height="22"><input type="text" name="Field4" size="50"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="44">City/State/Zip</td>
      <td width="374" height="44"><input type="text" name="Field5" size="35"
      value=""> <select name="Field6" size="1">
<option>AL<option>AK<option>AS<option>AZ<option>AR<option>CA<option>CO<option>CT<option>DE<option>DC<option>FM<option>FL<option>GA<option>GU<option>HI<option>ID<option>IL<option>IN<option>IA<option>KS<option>KY<option>LA<option>ME<option>MH<option>MD<option>MA<option>MI<option>MN<option>MS<option>MO<option>MT<option>NE<option>NV<option>NH<option>NJ<option>NM<option>NY<option>NC<option>ND<option>MP<option>OH<option>OK<option>OR<option>PW<option>PA<option>PR<option>RI<option>SC<option>SD<option>TN<option>TX<option>UT<option>VT<option>VI<option>VA<option>WA<option>WV<option>WI<option>WY      </select> <input type="text" name="Field7" size="10"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="36">Home Phone</td>
      <td width="374" height="36"><input type="text" name="Field8" size="15"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="36">Office Phone</td>
      <td width="374" height="36"><input type="text" name="Field9" size="15"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="23">E-Mail</td>
      <td width="374" height="23"><input type="text" name="Field10" size="50"
      value=""></td>
    </tr>
    <tr>
      <td width="124" height="23">File Upload</td><td width="425"><input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"><input type="file" id="file1" name="file[]" size="50"></td>
    </tr>
    <tr>
      <td rowspan="3" width="105" valign="top" height="45">&nbsp;</td>
    </tr>
    <tr>
      <td width="124" height="1"></td>
      <td width="374" height="1"></td>
      <td height="1" width="61">
      <input type="submit" value="Submit" name="submit" onClick="validateForm();"></td>
    </tr>
  </table>
</form>
</body>
</html>[/code]

Share this post


Link to post
Share on other sites
It's sending blank email because your mailing script is not on the action page (the upload handler page)

Just cut this code
[code]
$to = 'sold@photocardsandcalendars.com';
$subject = 'Calendar Sold';
$name = $_POST['BillingName'] . "\r\n" . $_POST['BillingCompany'] . "\r\n" . $_POST['BillingAddr1'] . "\r\n" . $_POST['BillingAddr2'] . "\r\n" . $_POST['BillingCity'] . "\r\n" . $_POST['BillingState'] . "\r\n" . $_POST['BillingZip'] . "\r\n" . $_POST['BillingPhone1'] . "\r\n" . $_POST['BillingPhone2'] . "\r\n" . $_POST['BillingEmail'];
$message = $name;
$headers = 'From: sales@photocardsandcalendars.com' . "\r\n";

mail($to, $subject, $message, $headers);
[/code]

into the upload hander

Share this post


Link to post
Share on other sites

×

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.