Sunday 5 January 2020

php - 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.



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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...