Jump to content
clintrivest

HTHL/PHP says submission worked, but no email

Recommended Posts

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!

Share this post


Link to post
Share on other sites

You know PHPMailer works but you're not using it? You should. That could easily fix your problem.

Share this post


Link to post
Share on other sites

Your form inputs do need the name="name" and name="email" added for your $_POSTS.

Also, this is just to educate me. Why did you add a "@" in front of the mail()? I looked it up and I couldn't find anything telling me what this means. Thanks!

Share this post


Link to post
Share on other sites
6 minutes ago, cutielou22 said:

Also, this is just to educate me. Why did you add a "@" in front of the mail()? I looked it up and I couldn't find anything telling me what this means. Thanks!

It's probably better not to know. ? The @ symbol is for error suppression. More information can be found here:
https://www.php.net/manual/en/language.operators.errorcontrol.php

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.