cannot get basic php email form to work

I have tried 3 different tutorials on how to set up a php email form. All i want it to do, is email me the contents of my form. There are only 2 fields in the form, name and email. It neither sends me an email, nor re-direct to the thanks page.

The form’s “action” setting goes to the SendResults.php, on which the code reads (originally copied from the tutorial & adjusted for my own use):

<?php //--------------------------Set these paramaters-------------------------- $subject = 'Email list subscriber result'; $emailadd = [email]'[email protected][/email]; $url = ''; $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: '.$emailadd.''); echo ''; ?>

Please help! I have been struggling to make this work for a couple of weeks. It should be pretty striaght forward, right?!!!

Hi there,

I don’t know if this is a problem that arose from posting the code, but in the line quoted below you are missing the trailing ’ from your string.

$emailadd = '[email protected];

If not, put [php]error_reporting(E_ALL);[/php] at the top of your script, have a look at the errors and let us know what exactly the problems are.

Good Luck.


The missing ’ isn’t the problem, and when I typed the error_reporting(E_ALL); into the top of the code, it didn’t appear to do anything, only print this to the page. To see what i am looking at, go to When a visitor types in their name and email on the home page ( instead of going to my thanks page, it opens the SendReuslts.php.

Thanks for your help, I am very confused!

I have finally worked it all out. The 3 tutorials i had tried were CRAP. I’m not experienced enough with PHP to say what exactly they did wrong, but i have found my solution by following the guidelines set out at

Thanks for your help with my problem, if (and when) I next have php problems this will be the first place i look to!


Sponsor our Newsletter | Privacy Policy | Terms of Service