我在PHP项目中创建了一个联系表单,我一直在尝试发送邮件,在此过程中我一直在改变一些代码,例如删除我的联系表单。现在我重新添加了表单,但它没有显示在浏览器上:
这是名为contact.php的实际文件:
<?php
define("TITLE", "Contact Us | MicroUrb");
include('includes/header.php');
/**
* PHPMailer Autoloader
*/
require '../vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
/**
* Configure PHPMailer with your SMTP server settings
*/
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'myemail@example.com';
$mail->Password = 'secret';
$mail->SMTPSecure = 'tls';
/**
* Enable SMTP debug messages
*/
$mail->SMTPDebug = 2;
/**
* Send an email
*/
$mail->setFrom('sender@gmail.com');
$mail->addAddress('recipient@gmail.com');
$mail->Subject = 'An email sent from PHP';
$mail->Body = 'This is a test message';
if ($mail->send()) {
echo 'Message sent!';
} else {
echo 'Mailer error: ' . $mail->ErrorInfo;
}
?>
<div id="contact">
<hr>
<h1 class="contact">Get in touch with us!</h1>
<form method="post" action="" id="contact-form">
<label for="name">Your name</label>
<input type="text" id="name" name="name">
<label for="email">Your email</label>
<input type="email" id="email" name="email">
<label for="message">and your message</label>
<textarea id="message" name="message"></textarea>
<input type="checkbox" id="subscribe" name="name" value="Subscribe">
<label for="">Subscribe to newsletter</label>
<input type="submit" class="button next" name="contact_submit" value="Send Message">
</form>
<hr>
</div>
<?php include('includes/footer.php'); ?>