-1

I would use PHPMailer with a contact form but I am doing something wrong because it doesn't work.

<?php

require ("class.phpmailer.php");

if (isset($_POST['submit'])) {
    $name=$_POST['name'];
    $subject=$_POST['subject'];
    $email=$_POST['email'];
    $message=$_POST['message'];

$mail = new PHPMailer();

$mail->IsSMTP();
$mail->Host = "smtp.mail.com";

$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Username = 'myemail@mail.com';
$mail-> Password = 12345;

$mail->From = ($email);
$mail->FromName = ($name);
$mail->addAddress = 'myemail@mail.com';

$mail->isHTML(false);

$mail->Subject = "Enquiry from Website submitted by $name";
}

if (!$mail->Send()) {
    echo "<script>alert('Submission failed.');</script>";``
}
else {
    echo "<script>alert('Email has been sent successfully.');</script>";
}
?>

Would you be so kind to give me a little big help? I don't understand where I'm doing wrong.

Thank you.

Kalamarico
  • 5,466
  • 22
  • 53
  • 70
John Shot
  • 296
  • 3
  • 11
  • 2
    try to be more specific than it doesn't work like does it crash or what doesn't work – tung Dec 07 '18 at 15:40
  • You're right sorry, whet i try to send an email from the form I get "Submission failed". – John Shot Dec 07 '18 at 16:45
  • 1
    You have [$mail->SMTPDebug = 2](https://github.com/PHPMailer/PHPMailer/wiki/SMTP-Debugging). Have you inspected the debug output? – Álvaro González Dec 07 '18 at 17:57
  • You need to heavily revise your question. Please read [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and then *edit* your question and update it so it is **clear**, **concise** and **specific** as well as showing your relevant [error logs](https://stackoverflow.com/questions/5127838/where-does-php-store-the-error-log-php5-apache-fastcgi-cpanel) and [debug](https://github.com/PHPMailer/PHPMailer/wiki/SMTP-Debugging) information. Thank you. – Martin Dec 07 '18 at 18:15

1 Answers1

0

If you inspect debug output you can find a hint. Most possible reasons are incorrect parameters or maybe smtp server rejects request.

Please post debug output.

Zortext
  • 566
  • 8
  • 21