0

I have been struggling with this php script, basically I want to send a email when the user submits the form by executing the php. I am quite new on the php language and I am not sure whether it is the webhost that prevents emails from sending and or my php configuration is wrong (I don't know to to change the configurations). I cannot find anything wrong with my php code and was hoping you guys can share some help.

I have submitted the form via a localhost where is sends perfectly, but when connected to my webhost it only alerts that something went wrong.

I have searched for various other questions but I am not managing, and I will appreciate any help. I have inserted the php into the html code but should actually be a external file, I just don't know where to insert php coding on stackoverflow.

form {
  margin: 0 auto;
  width: 80%;
  height: auto;
}
/*Style the text boxes*/

input,
textarea {
  width: 80%;
  height: 20px;
  background-color: #efefef;
  border: 1px solid #dedede;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
  padding: 10px;
  margin-top: 3px;
  font-size: 0.9em;
  font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
  color: #3a3a3a;
  border-radius: 5px;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
}
input:focus,
textarea:focus {
  border: 1px solid #97d6eb;
}
textarea {
  height: 213px;
  width: 90%;
}
#submit,
#reset {
  width: 10%;
  height: 38px;
  background-color: #161616;
  color: #FFFFFF;
  border: none;
  margin-top: 20px;
  cursor: pointer;
}
#submit:hover,
#reset:hover {
  opacity: 0.9;
  color: #755378;
}
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<form method="POST" action="index.php" target="" accept="text/html" formenctype="multipart/form-data">
  <label>Name &amp; Surname:</label>
  <input name="name" placeholder="Type Here..." required="">

  <label>Email:</label>
  <input name="email" type="email" placeholder="Type Here..." required="">

  <label>Subject:</label>
  <input name="subject" placeholder="Tour your interested in:">

  <label>Message:</label>
  <textarea name="message" placeholder="Inquiry"></textarea>

  <input id="submit" name="submit" type="submit" value="Submit">
  <input id="reset" name="reset" type="reset" value="Reset">

</form>

<?php

    error_reporting(-1);
    ini_set('display_errors', 'On');
    set_error_handler("var_dump");

    ini_set("mail.log", "/tmp/mail.log");
    ini_set("mail.add_x_header", TRUE);


 $name = $_POST['name'];
 $email = $_POST['email'];
 $message = $_POST['message'];
 $from = 'From: ';
 $to = 'eleccon@global.co.za';
 $subject = $_POST['subject'];
 
 
 $body = " From: $name\n E-mail: $email\n Subject: $subject\n Message:\n $message";
 
 if (isset($_POST['submit']))
 {
  /* Anything that goes in here is only performed if the form is submitted */
  if (mail ('eleccon@global.co.za', $subject, $body, $from))
  {
   echo "<script type='text/javascript'>alert('Your Message has been sent! Press OK to continue');</script>";
  } else
  {
   echo "<script type='text/javascript'>alert('Something went wrong, go back and try again');</script>";
  }
 }
?>
</body>
Frana
  • 75
  • 13

0 Answers0