Jump to content


Photo

HTHL/PHP says submission worked, but no email


  • Please log in to reply
2 replies to this topic

#1 clintrivest

clintrivest
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 15 December 2017 - 04:13 AM

Hi everyone!

I'm almost ready to launch my website promoting my computer training business. Unfortunately, I'm having trouble with my contact form. As far as I can tell, it should be working. I've had others examine it as well, and say it should work. I know PHPMailer is working on my server, I did a test. Following is the code for the html and php:

 

HTML

<form id="form" method="POST" action="bat/contact.php">
      <div class="success_wrapper">
      <div class="success">Contact form submitted!<br>
      <strong>We will be in touch soon.</strong> </div></div>
      <fieldset>
      <label class="name">
      <input type="text" value="Name:">
      <br class="clear">
      <span class="error error-empty">*This is not a valid name.</span><span class="empty error-empty">*This field is required.</span> </label>
      <label class="email">
      <input type="text" value="E-mail:">
      <br class="clear">
      <span class="error error-empty">*This is not a valid email address.</span><span class="empty error-empty">*This field is required.</span> </label>
      <label class="phone">
      <input type="tel" value="Phone:">
      <br class="clear">
      <span class="error error-empty">*This is not a valid phone number.</span><span class="empty error-empty">*This field is required.</span> </label>
      <label class="message">
      <textarea>Message:</textarea>
      <br class="clear">
      <span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>
      <div class="clear"></div>
      <div class="btns"><a data-type="reset" class="btn">clear</a><a data-type="submit" class="btn">submit</a>
      <div class="clear"></div>
      </div></fieldset></form>

PHP:

<?php 

if(isset($_POST['submit'])) {     
// EDIT THE 2 LINES BELOW AS REQUIRED
//$email_to = "crivest@solsticetraining.ca";
$email_to = "crivest@solsticetraining.ca";


// EDIT THE 2 LINES BELOW AS REQUIRED
//$sender = "crivest@solsticetraining.ca";
$sender = "crivest@solsticetraining.ca";
    
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$phone = $_POST['phone']; // required
$message = $_POST['message']; // required

$email_message = "Form details below.\n\n";

$email_subject = "Contact details - $name";
 
function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}
 
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Phone: ".clean_string($phone)."\n";
$email_message .= "Message: ".clean_string($message)."\n";

 
 
// create email headers
$headers = 'From:'.$sender."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
$sent= @mail($email_to, $email_subject, $email_message, $headers); 

if($sent){
        echo "<script>alert('Contact form submitted! We will be in touch soon.')
        location.replace('index4.html')
</script>";
}
else {
echo "<script>alert('Sorry! Something went wrong')
        location.replace('index-4.html')
</script>";


  }
}
?>

Maybe I'm missing something obvious. First, I'd like to see the form actually work. Then I can worry about security. The form can be seen at www.solsticetraining.ca/index-4.html

 

Thanks for all the help!



#2 requinix

requinix
  • Administrators
  • Impoverished Administrator
  • 9,873 posts
  • LocationWA

Posted 15 December 2017 - 06:30 AM

You know PHPMailer works but you're not using it? You should. That could easily fix your problem.
"Basically, I think the general rule of thumb is: if someone really wants the blood that's inside of your body, and they're like a vampire, or a dracula, or some sort of man-squito, then that's probably okay. A dracula and a man-squito are made for removing things like blood and swords from inside your body. That's basically fine. If something wants to get at your blood and they're, say, some kind of murdersaurus, or maybe a really big frog, that's where the problems start to arise. A really big frog is not made for removing blood, and your blood knows this, which is why it is so vehement about wanting to stay in your body instead of coming out. Unfortunately this will not deter a really big frog because a really big frog is full of things like prizes, and value, and quite a lot of hatred, and it would really rather like to replace any and all of those things with your blood, and basically by any means possible." --slumbermancer

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,164 posts

Posted 15 December 2017 - 05:57 PM

It may work better if you give names to your form's input fields
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users