Jump to content

Mig

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Mig's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. But this code is from contact.php. It's not going anywhere..? Anyway I tried that but still no emails.
  2. Ok, I have simplified the code even more and still no emails. Surely there is nothing wrong with this code: [code]<?php $errmsg = ""; $name = ""; $email = ""; $subject = ""; $message = ""; if(isset($_POST["send"])) { $name = $_POST["name"]; $subject = $_POST["subject"]; $message = $_POST["message"]; $to = "example@site.com"; mail($to, $subject, $message); } else { ?>       <table width="100%" style="margin-top:20px;">         <form id="contactform" name="contactForm" method="post">           <tr height="25px">             <td width="70px" align="right" ><h2 class="contactTitle">Name:&nbsp;&nbsp;</h2></td>             <td><input type="text" id="name" name="name" size="40" class="contactField" value="<?=$name;?>"></td>           </tr>           <tr height="25px">             <td align="right"><h2 class="contactTitle">Email:&nbsp;&nbsp;</h2></td>             <td><input type="text" id="email" name="email" size="40" class="contactField" value="<?=$email;?>"></td>           </tr>           <tr>             <td>&nbsp;</td>           </tr>           <tr height="35px">             <td align="right"><h2 class="contactTitle">Subject:&nbsp;&nbsp;</h2></td>             <td><input type="text" id="subject" name="subject" size="40" class="contactField" value="<?=$subject;?>"></td>           </tr>           <tr>             <td valign="top" align="right"><h2 class="contactTitle">Message:&nbsp;&nbsp;</h2></td>             <td><textarea rows="10" id="message" name="message" cols="60" class="contactField"><?=$message;?></textarea></td>           </tr>           <tr height="35px">             <td>&nbsp;</td>             <td><input type="submit" id="send" name="send" value="Send Message"></td>           </tr>         </form>       </table>       <?php } ?> [/code]
  3. No, sorry that was just a typo when I posted the code here. I changed it to be more simple so that I could make sure there were absolutely no errors with validation or concatenation or something. I've change the £ to a $ now. The email address I just changed just as an example. I have tried it with 3 real addresses, none of which receive email.
  4. Ok, I am sure contact form questions get asked here like 1000 times a day, but this really has me stumped. I just don't receive any emails. I tested the mail() function and it returns true so I don't know why I don't receive an email. Here is my code: [code]<?php $errmsg = ""; $name = ""; $email = ""; $subject = ""; $message = ""; if(isset($_POST["send"])) { $name = trim($_POST["name"]); $email = trim($_POST["email"]); $subject = trim($_POST["subject"]); $message = trim($_POST["message"]); if ($name == "") { $errmsg = "Please enter your name"; } else if (!preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $email)) { $errmsg = "Invalid email address"; } else if ($message == "") { $errmsg = "Please enter a message"; } if ($errmsg == "") { $to = "example@site.com"; mail($to, $subject, $message) ?>       <div style="margin-top:60px; text-align:center; height:160px">         <h1>Thank you for your message.</h1>         <p><a href='#'>Return to Home page</a></p>       </div> <?php } } if (!isset($_POST["send"]) || $errmsg != "") { ?>       <div id="error" class="contactFormError"><?=$errmsg;?></div>       <table width="100%" style="margin-top:20px;">         <form id="contactform" name="contactForm" method="post">           <tr height="25px">             <td width="70px" align="right" ><h2 class="contactTitle">Name:&nbsp;&nbsp;</h2></td>             <td><input type="text" id="name" name="name" size="40" class="contactField" value="<?=$name;?>"></td>           </tr>           <tr height="25px">             <td align="right"><h2 class="contactTitle">Email:&nbsp;&nbsp;</h2></td>             <td><input type="text" id="email" name="email" size="40" class="contactField" value="<?=$email;?>"></td>           </tr>           <tr>             <td>&nbsp;</td>           </tr>           <tr height="35px">             <td align="right"><h2 class="contactTitle">Subject:&nbsp;&nbsp;</h2></td>             <td><input type="text" id="subject" name="subject" size="40" class="contactField" value="<?=$subject;?>"></td>           </tr>           <tr>             <td valign="top" align="right"><h2 class="contactTitle">Message:&nbsp;&nbsp;</h2></td>             <td><textarea rows="10" id="message" name="message" cols="60" class="contactField"><?=$message;?></textarea></td>           </tr>           <tr height="35px">             <td>&nbsp;</td>             <td><input type="submit" id="send" name="send" value="Send Message"></td>           </tr>         </form>       </table>       <?php } ?>[/code] I've edited out all the unnecessary stuff from the HTML here and also simplified the php so that it's not getting anything wrong with validation or something. Still, I get no emails. I've tried different email addresses too. It's not in Junk either.
  5. Hi, I've just started learning PHP, and I'm trying to finish a contact form I've made. I have [i]contact.htm [/i] which goes to [i]mailer.php[/i]. I have written some JavaScript validation of the form, and I am going to use server-side validation too. Problem is, (let's say JS is turned off) I have no idea how to go back to the contact form if the input is incorrect, with the values still in the fields, then display the relevant error message. I was thinking I could have some error messages with [b]display:none[/b], which I then switch to [b]display:inline[/b] but I really have no idea how to do that with PHP (if you can at all). Ok, basically, how do I send the user back to contact.htm after PHP validation fails, with the form remaining as it was, and alert them to the errors? Thanks. [b]Edit:[/b] I understand how to do it if I just use one php page. Is this advisable?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.