posting contact form to email using php not working -
i have created 'coming soon' landing page new website. until website design , development has been completed want able collect interested parties email addresses - should submit directly email. have written below code, not receiving emails address during testing:
html:
form method="post" name="myemailform" action="emailform.php"> <div id="subscribe"> <input type="text" placeholder="enter email address..." name="emailaddress" id="emailaddress"> <input type="submit" value="submit"> <div class="clear"></div> </div> </form> php:
<?php if(!isset($_post['submit'])) { //this page should not accessed directly. need submit form. echo "error; need hit submit"; } $visitor_email = $_post['emailaddress']; $email_from = $_post['emailaddress']; // validate first if(empty($visitor_email)) { echo "email address required"; exit; } $email_from = 'myemail@gmail.com'; $email_subject = "new form"; $email_body = "you have received new notifcation $visitor_email.\n". $to = "myemail@gmail.com"; $headers = "from: $email_from \r\n" // send email mail($to,$email_subject,$email_body,$headers); ?> this first attempt @ server-side scripting. can see incorrect in code?
your conditional statement
if(!isset($_post['submit'])) is looking named submit button:
<input type="submit" value="submit"> which should be
<input type="submit" value="submit" name="submit"> - having error reporting on, have signaled
undefined indexerror.
also seem missing < form method="post" if actual code.
you're missing semi-colon in $headers = "from: $email_from \r\n"
which should read $headers = "from: $email_from \r\n";
plus,
$email_body = "you have received new notifcation $visitor_email.\n". remove dot @ end , replace semi-colon
$email_body = "you have received new notifcation $visitor_email.\n"; and use error reporting
being
error_reporting(e_all); ini_set('display_errors', 1); placed before opening <?php tag, signal errors if found in code.
sidenote:
this name="myemailform" don't need that.
Comments
Post a Comment