-1

I'm new to coding so i basically copied the below code from various sources until i thought it may work but it's not, what i need is to send form info from an html page to an email once filled. Please Help.

php code for the form:

<?php ini_set('display_errors',1);?>
$emailTo = '<abc@gmail.com>';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$Name=$_POST['Name']; 
$Mobile=$_POST['Mobile'];
$Email=$_POST['Email']; 
$City=$_POST['City'];
$emailIsValid = preg_match('/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-  
z]{2,4}$/', $Email);

if($Name && $Mobile $Email && $emailIsValid && $City){
$subject = "[Contact via Site] $subject";
$body = "Name: $Name <br /> Email: $Email <br /> Mobile: $Mobile <br /> City: $City";
$headers  = 'MIME-Version: 1.1' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
$headers .= "From: $name <$Email>" . PHP_EOL;
$headers .= "Return-Path: $emailTo" . PHP_EOL;
$headers .= "Reply-To: $Email" . PHP_EOL;

mail($emailTo, $subject, $body, $headers);
$emailSent = true;
} else {
$hasError = true;
}
}
?>

html code: Thank You, we'll call you soon error pls check all fields.

<div class="col-md-6 col-md-offset-3">
<form action="<?php echo $_SERVER['/Thanks.html']; ?>" id="FORM" class="form-horizontal"    
role="form" method="post" style="height: 300px; padding-left:10px; padding-top:10px;">


   <div class="formContainer" >
       <div class="label">
          <label>Name: </label>
       </div>
       <div class="textbox">
          <input type="text" id=name name="Name"/>
       </div> <br>
           <div class="label">
          <label>Mobile: </label>
       </div>
       <div class="textbox">
          <input type="tel" id=mobile name="Mobile" />
       </div> <br>
       <div class="label">
          <label>Email: </label>
       </div>
       <div class="textbox">
          <input type="email" id=email name="Email"/>
       </div> <br>
           <div class="label">
          <label>City: </label>
       </div>
       <div class="textbox">
          <input type="text" id=city name="City"/>
       </div> <br>
           <div class="submit">
           <input type="submit" value="Submit">
       </div> 
  </form>

1 Answers1

0

Just use this PHPMailer class.. It is optimized and fully featured to send emails, set attachments, change header attributes, etc... without even having to know how they are actually implemented: https://github.com/PHPMailer/PHPMailer

Siki
  • 111
  • 4