tags:

views:

64

answers:

4

Hi!

I'm trying to make a contactform. And somehow it won't work. I tried to send a email just with the mail()-function and that works. So I'm doing something wrong and I don't know what.

When you click on the submit button, I refer to the mailer.php file. Both file are in the same folder.

<?php
if(isset($_POST['sendButton']))
{
 $to = "[email protected]";
 $subject = "Contactformulier Portfolio";
 $name_field = $_POST['yourName'];
 $email_field = $_POST['yourEmail'];
 $message = $_POST['yourMessage'];

 $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

 echo "Data has been submitted to $to!";
 mail($to, $subject, $body);
}
else
{
 echo "There has been some error, try again please!";
}
?>
+2  A: 

Force PHP to show you the errors using the ini_set function. For example:

function enable_errors() {
  error_reporting( E_ALL );
  ini_set( 'display_errors', 1 );

  set_error_handler( "wms_error_handler" );
  register_shutdown_function( 'wms_shutdown' );
}

function wms_error() {
  echo "Print debugging here.";
}

function wms_error_handler($errno, $errstr, $errfile, $errline) {
  echo "Print debugging here.";
  wms_error();
  return true;
}

function wms_shutdown() {
  echo "Print debugging here.";

  if( is_null( $e = error_get_last() ) === false ) {
    wms_error();
  }
}

Then, in your code, call:

enable_errors();

Be sure to remove that line when you have finished debugging (to avoid accidentally exposing security-sensitive details of your application to the world).

Dave Jarvis
+1  A: 

Can you provide your HTML as well?

EDIT:

$_POST indeces are defined by the name attribute on your input elements. As you have only defined an id field on your submit input element, the condition you are checking is never met (and thus the mail is never send). Add the name attribute to your submit input element like this:

Anzeo
This is the complete HTML form<form action="mailer.php" method="post" name="offerMeAJob_form" id="offerMeAJob_form"><p class="formTitle">Your name...</p><input id="yourName" type="text" /><br /><p class="formTitle">Your email...</p><input id="yourEmail" type="text" /><br /><p class="formTitle">Your message...</p><textarea id="yourMessage"></textarea><br /><input id="sendButton" value="" type="submit" /></form>
Bjorn Seigers
$_POST indeces are defined by the name attribute on your input elements. As you have only defined an id field on your submit input element, the condition you are checking is never met (and thus the mail is never send). Add the name attribute to your submit input element like this: <input id="sendButton" name="sendButton" value="" type="submit" />
Anzeo
A: 

Without seeing all your code, my guess is that the condition for mailing is never met because there is no value set for the submit button. Try making the condition for emailing like this:

if($_POST) {
  Mail Here
} else {
  error case
}
bpeterson76
+2  A: 

Is your form button named "sendButton"? <input type='submit' name='sendButton' /> If not, there's your culprit.

Core Xii
I gave it an ID, isn't that good then?
Bjorn Seigers
No. `id`s are used to identify CSS classes and as anchors (for #links) - HTML forms need `name`s.
Core Xii