php - Mail Sending But Not On Submit? -


i php novice here. have send mail script looks this:

$to      = 'example@email.com'; $from    = 'noreply@email.com'; $subject = 'test submission'; $message = 'this test.'; $headers = 'from: example@email.com' . "\r\n" . // 'reply-to: example@email.com' . "\r\n" . 'x-mailer: php/' . phpversion();  mail($to, $subject, $message, $headers); 

this script works fine , sends e-mail when page loaded. problem when alter script enough form not submitted until submit button clicked of sudden nothing works anymore. here altered code have been trying use (and seems go right along php site suggests):

if(isset($_post['submit'])){     $to      = 'example@email.com';     $from    = 'noreply@email.com';     $subject = 'test submission';     $message = 'this test.';     $headers = 'from: example@email.com' . "\r\n" .     // 'reply-to: example@email.com' . "\r\n" .     'x-mailer: php/' . phpversion();      mail($to, $subject, $message, $headers);     } 

make sure submit button on form has name attribute. value of name attribute gets sent server, so:

<input type="submit" name="btnsubmit" value="go!">

...would result in variable , value:

$_post["btnsubmit"] = "go!";

...and check this:

if(isset($_post["btnsubmit"])) {   ... } 

Comments