Jump to content

PHP Form Mail


Ads901

Recommended Posts

Morning All

 

I have got an online form, which you can see via this link http://92.48.94.26/~theinval/market-monitor.co.uk/ig_contactus.html

 

It uses the below PHP form to process the form, sending it to an internal email address and redirecting to a thank you page. It is currently set out to use the email address that the user puts into the form as the 'From address' when it is sent - however when you submit the form you get the message 'Input is Empty' even though the email address is there.

 

Can anyone explain how I can fix this?

 

<?php 

ini_set('display_errors','On'); 

?>

<?php

 

//--------------------------Set these paramaters--------------------------

 

// Subject of email sent to you.

$subject = 'Enquiry from the Market Monitor website';

 

// Your email address. This is where the form information will be sent.

$emailadd = 'info@market-monitor.co.uk';

 

// Where to redirect after form is processed.

$url = 'http://92.48.94.26/~theinval/market-monitor.co.uk/ig1_contactthankyou.html';

 

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.

$req = '1';

 

// --------------------------Do not edit below this line--------------------------

$text = "Results from form:\n\n";

$space = ' ';

$line = '

';

foreach ($_POST as $key => $value)

{

if ($req == '1')

{

if ($value == '')

{echo "$key is empty";die;}

}

$j = strlen($key);

if ($j >= 20)

{echo "Name of form element $key cannot be longer than 20 characters";die;}

$j = 20 - $j;

for ($i = 1; $i <= $j; $i++)

{$space .= ' ';}

$value = str_replace('\n', "$line", $value);

$conc = "{$key}:$space{$value}$line";

$text .= $conc;

$space = ' ';

}

mail($emailadd, $subject, $text, 'From: '.$_POST["Email"].'');

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

?>

Link to comment
Share on other sites

<?php
mail($emailadd, $subject, $text, 'From: '.$_POST["Email"].'');
?>

It seems like your last argument in the mail function may not be liked.

mail  ( string $to  , string $subject  , string $message  [, string $additional_headers  [, string $additional_parameters  ]] )

 

Taken from http://us3.php.net/manual/en/function.mail.php

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

 

So try setting a $header var, and making it: $headers = 'From: ' . $_POST['Email']; and then send your mail function like the php.net example:

mail($emailadd, $subject, $text, $headers);

 

Seems worth a try to start.

Link to comment
Share on other sites

Ok as I am new to PHP just to clarify - just add the headers in at the top of the current script, is that what your saying?

 

What about the coding at the top that is already defining the to address, subject etc etc

Link to comment
Share on other sites

Sorry, let me apologize.  I misread, I thought you were having a problem with the mail function, not getting a $_POST value populated.  You should haven't to change anything yet from what I've said, apologies.

 

If it's telling you that the "email" section of the form is missing you could do a few debug things.  One would be a print_r($_POST) to show all the post values entered.  Verify that you're receiving a $_POST['Email'] field with some value.

Link to comment
Share on other sites

I think I found the problem, or at least where to look.  Shows on line 193ish for me.

You can search your code for <input name="input" type="checkbox" value="">  <-- This is what is showing up empty

 

It seems your checkboxes are screwy.  When I select "No" for ?Receive email updates?, it selects both yes and no.

You should either have one check box for "Yes", where unchecked == no.  Or use a RADIO button instead to avoid confusion.

Fix this section~

         <tr>
        <td class="Form_Headings">Would you like to recieve future email updates?</td>

        <td><label><span id="spryEmailUpdates">
        <input type="checkbox" name="Email Updates Yes" id="EmailUpdatesYes">
        <span class="Typestyle_body">Yes</span><span class="Typestyle_body">
        <input name="input" type="checkbox" value="">
        No</span> <span class="checkboxRequiredMsg">Please make a selection.</span></span></label></td>
      </tr>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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