Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form id="contact-form" method="post" action="contact.php">
- <input name="name" type="text" id="name" class="form-control" placeholder="Your name" required>
- <br>
- <input name="email" type="email" id="email" class="form-control" placeholder="Your email" required>
- <br>
- <textarea name="message" id="message" class="form-control" placeholder="Message" row="4" required></textarea><br>
- <input type="submit" class="form-control submit" value="SEND MESSAGE">
- </form>
- <?php
- use PHPMailerPHPMailerPHPMailer;
- use PHPMailerPHPMailerException;
- require 'C:PHPMailerPHPMailer-mastersrcException.php';
- require 'C:PHPMailerPHPMailer-mastersrcPHPMailer.php';
- require 'C:PHPMailerPHPMailer-mastersrcSMTP.php';
- $mail = new PHPMailer(TRUE);
- try {
- $mail->isHTML(true);
- $mail->setFrom('example@hotmail.com', 'Contact Form');
- $mail->addAddress('example@hotmail.com', 'Lewis');
- $mail->isSMTP();
- $mail->Host = 'smtp.gmail.com';
- $mail->SMTPAuth = TRUE;
- $mail->SMTPSecure = 'tls';
- $mail->Username = '*******';
- $mail->Password = '*****';
- $mail->Port = 587;
- $name = $_POST['name'];
- $email = $_POST['email'];
- $message = $_POST['message'];
- if ($mail->addReplyTo($_POST['email'], $_POST['name'])) {
- $mail->Subject = 'contact form';
- $mail->isHTML(true);
- $mail->Body = "There has been a message sent from our contact form from: $name
- <br>This is their message: $message
- <br>Please respond to them here: $email";
- //Send the message, check for errors
- if (!$mail->send()) {
- //The reason for failing to send will be in $mail->ErrorInfo
- $msg = 'Sorry, something went wrong. Please try again later.';
- } else {
- header("Refresh:3; url=index.php#contact");
- echo "Message sent! Thanks for contacting us. We aim to respond within 1 working day";
- }
- } else {
- $msg = 'Invalid email address, message ignored.';
- }
- /* Enable SMTP debug output. */
- $mail->SMTPDebug = 4;
- // $mail->send();
- }
- catch (Exception $e)
- {
- echo $e->errorMessage();
- }
- catch (Exception $e)
- {
- echo $e->getMessage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement