0

Hey guys I am trying to use PHP mailer to send an email through a contact form on my website.

I used these settings.

if (empty($errors)) {

    $m = new PHPMailer;
    $m->isSMTP();
    $m->SMTPAuth = true;

    $m->Host = 'smtp.gmail.com';
    $m->Username = 'myemail@gmail.com';
    $m->Password = 'its a correct password';
    $m->SMTPSecure = 'ssl';
    $m->Port = 465;
    $m->isHTML();
    $m->Subject = 'Submission of Contact form';
    $m->Body = 'From:' . $fields['name'] . ' (' . $fields['email'] . ')<p>' .
        $fields['message'] . '</p>';
    $m->FromName = 'Contact';
    $m->AddAddress('myemail@gmail.com', 'myname');
    if ($m->send()) {
        header('Location: thanks.php');
        die();
    } else {
        $errors[] = 'Sorry, Try again later.';
    }
}

I am new to PHP, but it seems that I have a syntax error somewhere that prevents the email from being sent. When I inspect the page I do get the 302 found and the 200 OK so it is working fine.

What am I missing in this code?

Synchro
  • 35,538
  • 15
  • 81
  • 104
Noopty
  • 13
  • 1
  • 4
  • Please indent the code, and post the error. If you can't see the error make sure you cant display them (http://stackoverflow.com/a/21429652/3806412) – Nil Llisterri May 28 '16 at 12:17
  • Possible duplicate of [PHP mail form doesn't complete sending e-mail](http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – luchaninov May 28 '16 at 12:27
  • Base your code on the [gmail example provided with PHPMailer](https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps), and read [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting). It's very likely this is a duplicate question. – Synchro May 28 '16 at 12:47

0 Answers0