so i want to send an email after submitting a HTML form, using PhpMailer. But when i click submit, my page simply refresh and there is no email in my inbox. What am i missing? also, what value should i assign to the action attribute?
This is my form
<form action="" method="POST" enctype="text/plain" id="contact-form">
<span class="contacts-text" id="first-contacts-text">compile this form.</span>
<span class="contacts-text">I will reply as soon as possible. Thank you!</span>
<ul class="form-content">
<li class="form-input">
<label for="name" class="label">Full name</label>
<input class="input" id="name" type="text" name="name" required>
</li>
<li class="form-input">
<label for="email" class="label">E-mail</label>
<input class="input" id="mail" type="text" name="email" required>
</li>
<li class="form-input">
<label for="msg" class="label">Insert text</label>
<textarea class="input" id="comment" type="text" name="msg" cols="30" rows="10" style="resize: none;" required></textarea>
</li>
<li class="form-input" id="last-input">
<input class="input" id="form-button" type="submit" value="submit" name="submit">
</li>
</ul>
</form>
and this is my php code
$result="";
if(isset($_POST['submit'])){
require 'phpMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->Host='smtp.gmail.com';
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->SMTPSecure='tls';
$mail->Username='my.own.business@gmail.com';
$mail->Password='myPassword';
$mail->setFrom($_POST['email'],$_POST['name']);
$mail->addAddress('my.own.business@gmail.com');
$mail->addReplyTo($_POST['email'],$_POST['name']);
$mail->isHTML(true);
$mail->Subject='Form Submission: '.$_POST['subject'];
$mail->Body='<h2 align=center> :'.$_POST['name'].'<br>Email: '.$_POST['email'].'<br>Message: '.$_POST['msg'].'</h2>';
if(!$mail->send()){
$result="Something went wrong. Please try again.";
}
else {
$result="Thanks ".$_POST['name']." for contacting me. I will get you back soon!";
}
}
?>
What am i missing?
You set the enctype
attribute to text/plain
which is not machine processable. Don't do that.
also, what value should i assign to the action attribute?
The URL of the PHP program.