0

I have a basic Contact form for my website, but I can not get it to work. The form acts like it is sending, but I never received the email from the form. It is using twitter bootstrap. I got the initial code from freehtml template. I have the form uploaded at www.tonyaespinoza.com/walnut/contact.html as a temporary location so I could have it uploaded to a server for testing.

Here is the HTML form:

<div class="col-md-6">
<form method="post" name="contactForm" role="form" id="contactForm" 
action="sendEmail.php">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea name="message" id="message" name="message" cols="30" rows="10" 
class="form-control"></textarea>
</div>
<div class="form-group">
<input type="submit" class="btn btn btn-special" value="Send Message">
<div class="submitting"></div>
</div>
</form>
<div id="form-message-warning"></div>
<div id="form-message-success">
Your message was sent, thank you!</div>
</div>

And here is the php:

$to = 'my_mail@yahoo.com';

function url(){
return sprintf(
"%s://%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
$_SERVER['SERVER_NAME']
);
}

if($_POST) {

$name = trim(stripslashes($_POST['name']));
$email = trim(stripslashes($_POST['email']));
$subject = trim(stripslashes($_POST['subject']));
$contact_message = trim(stripslashes($_POST['message']));

if ($subject == '') { $subject = "Contact Form Submission"; }

// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= nl2br($contact_message);
$message .= "<br /> ----- <br /> This email was sent from your site " . 
url() . " contact form. <br />";

// Set From: header
$from =  $name . " <" . $email . ">";

// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

ini_set("sendmail_from", $to); // for windows server
$mail = mail($to, $subject, $message, $headers);

if ($mail) { echo "OK"; }
else { echo "Something went wrong. Please try again."; }

}

?>
teeyo
  • 3,665
  • 3
  • 22
  • 37
T.Esp
  • 1
  • 1
  • well for one thing, you have 2 of the same name attributes in this ` – Funk Forty Niner Oct 05 '17 at 15:38
  • If the `mail()` function is returning a truthy value then your issue is likely with the email server. Your host may not allow off-server mails and you may have to use an email API like Mailgun. – Alex Howansky Oct 05 '17 at 15:39
  • @teeyo that's the form, they're using `action="sendEmail.php"` being another file. Edit: you deleted what I was responding to. *Deleting......................................* – Funk Forty Niner Oct 05 '17 at 15:40
  • Took the extra name out and still doesn't work. – T.Esp Oct 05 '17 at 15:41
  • @Fred-ii- I skipped that sorry, I think it may go to **spam** or the `mail` function is blocked by the host, I had that issue once – teeyo Oct 05 '17 at 15:42
  • *"I have the form uploaded at www.tonyaespinoza.com/walnut/contact.html as a temporary location so I could have it uploaded to a server for testing."* - This I don't get. If that server isn't setup to handle mail or is blacklisted or Lord knows what, then why put it on that server? If your `if ($mail) { echo "OK"; }` shows "OK", then mail did its job. It's up to you to troubleshoot it. – Funk Forty Niner Oct 05 '17 at 15:47
  • How do I know if "echo" returned "ok"? – T.Esp Oct 05 '17 at 20:38

0 Answers0