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 = '[email protected]';

 

// 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
https://forums.phpfreaks.com/topic/109857-php-form-mail/
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      = '[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);
?>

 

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
https://forums.phpfreaks.com/topic/109857-php-form-mail/#findComment-563742
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
https://forums.phpfreaks.com/topic/109857-php-form-mail/#findComment-563755
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
https://forums.phpfreaks.com/topic/109857-php-form-mail/#findComment-563758
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.