Won't send an e-mail

Asked by At

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.

<?php
include(HPHMailerAutoload);
$result="";
if(isset($_POST['submit'])){
require 'PHPMailerAutoload.php';
$mail->Host='smtp.gmail.com';
$mail->Port=587;
$mail->SMTPSecure='tls';
$mail->Username='[email protected]';
$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'; 
}
?>

1 Answers

1
Danyal Sandeelo On Best Solutions

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
}