0

I used PHPMailer on my website and it worked for around 10 emails and then it stopped and now gives me this error:

Message could not be sent.Mailer Error: Could not instantiate mail function.

Also do I need ->IsSMTP for personal emails?

As I said, it worked for the first 10 emails and then I got the error.

This is my suggestion.php:

ini_set('display_errors', 1);

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = trim(filter_input(INPUT_POST,"name",FILTER_SANITIZE_STRING));
    $email = trim(filter_input(INPUT_POST,"email",FILTER_SANITIZE_EMAIL));
    $details = trim(filter_input(INPUT_POST,"details",FILTER_SANITIZE_SPECIAL_CHARS));

    if ($name == "" || $email == "" || $details == "") {
        echo "Please fill in the required fields: Name, Email and Details";
        exit;
    }
    if ($_POST["address"] != "") {
        echo "Bad form input";
        exit;
    }
    require("inc/phpmailer/class.phpmailer.php");
    $mail = new PHPMailer;

    if (!$mail->ValidateAddress($email)) {
        echo "Invalid Email Address";
        exit;
    }
    //$mail->IsSMTP();
    $email_body = "";
    $email_body .= "Name: " . $name . "<br>";
    $email_body .= "Email: " . $email . "<br>";
    $email_body .= "Customer Question: " . $details . "<br>";


    $mail->setFrom($email, $name);
    $mail->addAddress('arisconstantinou@cytanet.com.cy', 'Author');     // Add a recipient

    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = 'Customer Question ' . $name;
    $mail->Body    = $email_body;

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
        exit;
    }


    header("location:suggest.php?status=thanks");
}
?>
benomatis
  • 5,035
  • 7
  • 30
  • 51
ELITE1990
  • 3
  • 4
  • 1
    Have you looked through https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting yet? Which of the [approaches for similar questions on SO](https://www.google.de/search?q=site:stackoverflow.com+phpmailer+could+not+instantiate+mail+function) have you tried? – mario Mar 26 '16 at 20:01
  • I replied to your question [on github](https://github.com/PHPMailer/PHPMailer/issues/670) – Synchro Mar 27 '16 at 08:12
  • Possible duplicate of [Could not instantiate mail function. Why this error occuring](http://stackoverflow.com/questions/1944631/could-not-instantiate-mail-function-why-this-error-occuring) – Synchro Mar 27 '16 at 08:12

0 Answers0