简体   繁体   中英

Won't send an e-mail

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='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'; 
}
?>

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM