So I'm using PHPAutoload to send an e-mail. However the mail won't send. I made a contact form where I ask for your name, subject and message and implemented that into my php code. Can anybody help me?
Thanks in advance.
include(HPHMailerAutoload);
$result="";
if(isset($_POST['submit'])){
require 'PHPMailerAutoload.php';
$mail->Host='smtp.gmail.com';
$mail->Port=587;
$mail->SMTPSecure='tls';
$mail->Username='test@test.com';
$mail->Password='******';
$mail->setFrom($_POST['email'], $_POST['name']);
$mail->addAddress('email');
$mail->addReplyTo($_POST['email'], $_POST['name']);
$mail->isHTML(true);
$mail->Subject='Test ';
$mail->Body='Test';
}
?>
Answer
You forgot to call send()
so add this code after $mail->Body='Test';
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo; // you can redirect to an error page
} else {
echo 'Message sent!'; // you can redirect to a thank page
}
No comments:
Post a Comment