Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Form submit nightmare

the mail() function

Moderators: macek, egami, gesf

Form submit nightmare

Postby linardzb » Wed Aug 29, 2012 1:14 pm


Im trying to submit the email through the online contact page I cannot receive emails through it, im not sure where is the problem with the code. It seems to be working fine for other people through fiddle or some other tool. I'm providing the code for the form too. any feedback welcome, cheers

My PHP is:
Code: Select all
      $error = false;
      $sent = false;
      if(isset($_POST['name'])) {
         if(empty($_Post['name']) || empty($_POST['email']) || empty($_POST['comments'])) {
            $error = true;
         } else {
         $to = "";
         $name = trim($_POST['name']);
         $email = trim($_POST['email']);
         $comments = trim($_POST['comments']);
         $subject = "Contact Form";
         $messages =  "Name: $name \r\n Email: $email \r\n Comments: $comments";
         $headers = "From:" . $name;
         $mailsent = mail($to, $subject, $messages, $headers);
         if($mailsent) {
            $sent = true;

and my HTML is:
Code: Select all
<?php if($error == true) { ?>
    <p class="error"></p>
    <?php } if($sent == true) { ?>
    <p class="sent"></p>
    <?php } ?>   
    <div id="form">
       <form name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
             <h4>Contact Me!</h4>
             <label for="name">Name:</label>
                <input type="text" name="name" id="name"/>
                <label for="email"/>Email:</label>
                <input type="text" name="email" id="email"/>
                <label for="comments" id="comments">Comments:</label>
                <textarea name="comments" id="" width="90%"></textarea>
                   <input class="btn" type="submit" name="submit" class="submit" value="Send email"/>
                   <input class="btn" type="reset" value="Reset"/>           

Many thanks
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Aug 29, 2012 1:09 pm

Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.