0

I am trying to send an email through a contact form with PHPMailer. I have looked at tutorials, because I have never used PHPMailer before. This is what I have come up with, But It does not send the email?

<?php
require_once 'mail/PHPMailerAutoload.php'; // this will include smtp and pop files.
if(isset($_POST['submit'])) {
    $email_to = "jacksonhogan01@gmail.com";

    // validation expected data exists
    if(!isset($_POST['name']) ||!isset($_POST['address']) ||!isset($_POST['subject']) ||!isset($_POST['message'])){
        died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $name = $_POST['name']; // required
    $address = $_POST['address']; // required
    $subject = $_POST['subject']; // required
    $message = $_POST['message']; // required

    $email_message = "\n\n";
    $email_message .= "Name: ".$name."\n";
    $email_message .= "Email: ".$address."\n";
    $email_message .= "Subject: ".$subject."\n";
    $email_message .= "Message: ".$message."\n";

    $mail = new PHPMailer();
    $mail->isSendmail();
    $mail->setFrom($address, $name);
    $mail->addAddress($email_to, 'GramsandPops');
    $mail->Subject = $subject;

    if (!$mail->send()) { //send the message, check for errors
        echo "Mailer Error: " . died($error);
    } else {
        header('Location: contact.php?result=success');
    }
}
?>

<div id="contact" class="container">
    <div class="contactheader">
        <p>Contact</p>
    </div>
    <form class="form-horizontal"
        style="padding-right: 50px; padding-left: 50px; padding-top: 20px;"
        action="" method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label class="control-label col-sm-2">Name:</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="name"
                    placeholder="Name...">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">Email:</label>
            <div class="col-sm-10">
                <input type="email" class="form-control" name="address"
                    placeholder="Email..">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">Subject:</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="subject"
                    placeholder="Subject..">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">Message:</label>

            <div class="col-sm-10">
                <textarea class="form-control" cols="40" id="message"
                    name="message" rows="10" placeholder="Message.."></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-10" style="text-align: center;">
                <button style="width: 100px" type="submit" name="submit"
                    id="submit" class="btn btn-default">Send!</button>
            </div>
        </div>
    </form>
</div>

I have the correct file path for the PHPMailerAutoload.php I'm not sure what could be causing this. Thanks for any help.

  • 1
    What is the error/notice/warning are you getting? – Amit Merchant Feb 06 '18 at 03:28
  • Are you on windows? If so there is no inherent mail server and so you will need to set up a relay to make it work. – Paul Coldrey Feb 06 '18 at 04:28
  • You're writing new code using an old version, never a good idea. It's also extremely unlikely you really want to use `isSendmail()`. Base your code on [the contact form example provided with PHPMailer](https://github.com/PHPMailer/PHPMailer/blob/master/examples/contactform.phps). – Synchro Feb 06 '18 at 08:06

0 Answers0