1

I need your help. Might be quite simple, but as I am new to PHP I cant figure out what causes this problem.

I am trying to set up a simple contact form with attachment and get these information send via phpmailer. I test it via xampp. But even before I press the send-button it shows: Could not instantiate mail function

When I enter sth in the contact form and press the button, it shows the same error. May I have sth completely wrong in the code?

So this is my HTML:

<form method="post">
    <input style="width: 100%;" type="text" name="name" placeholder="Ihr Name..." required/><br>
    <input style="width: 100%;" type="email" name="email" placeholder="Ihre Email-Adresse..." required/><br>
    <input style="width: 100%;" type="text" name="phone" placeholder="Ihre Telefonnummer..." /><br>
    <textarea style="padding: 10px 12px; width: 100%;"name="quote" rows="6" placeholder="Ihre Nachricht..." required></textarea><br>
    <input name="uploaded_file" type="file" size="50" style="margin-top: 10px;">
    <button type="submit" class="button" name="Send" style="width:100%; margin-top:10px; text-align: center;">Anfrage absenden!</button>
</form>

this is my php:

<?php
  //Klasse einbinden
  require('class.phpmailer.php');

  //Instanz von PHPMailer bilden
  $mail = new PHPMailer();

  //Absenderadresse der Email setzen
  $mail->From = $_POST['email'];

  //Name des Absenders setzen
  $mail->FromName = $_POST['name'];

  //Empfängeradresse setzen
  $mail->AddAddress("example@gmx.de"); 

  //Betreff der Email setzen
  $mail->Subject = "Anfrage via Website";

  //Text der EMail setzen
  $mail->Body = $_POST['quote'];

  if (isset($_FILES['uploaded_file']) &&
    $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
    $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
                         $_FILES['uploaded_file']['name']);
  }



  //EMail senden und überprüfen ob sie versandt wurde
  if(!$mail->Send())
  {
     //$mail->Send() liefert FALSE zurück: Es ist ein Fehler aufgetreten
     echo "Die Email konnte nicht gesendet werden";
     echo "Fehler: " . $mail->ErrorInfo;
  }
  else
  {
     //$mail->Send() liefert TRUE zurück: Die Email ist unterwegs
     echo '<p>Vielen dank für Ihre Anfrage. Sie erhalten in Kürze Ihr Angebot von mir!</p>';
  }
?>

Do you know, what I am doing wrong in here? Thanks for your help! :-)

PS: Do you have some advice, to make this a secure form as it might contain sensitive attachments (I have SSL implemented)?

Krystian
  • 537
  • 3
  • 13
  • 44
  • 2
    Xammp does not include a mail server. You need to also install a mail server (or activate it depending on your os) and then configure it in your php.ini – Dustin Poissant Apr 01 '17 at 02:04
  • 2
    Possible duplicate of [phpmailer error "Could not instantiate mail function"](http://stackoverflow.com/questions/1297084/phpmailer-error-could-not-instantiate-mail-function) – Sahil Gulati Apr 01 '17 at 02:21
  • 1
    Try to use gmail smtp for sending email using phpmailer in xampp – Adhan Timothy Younes Apr 01 '17 at 02:24

0 Answers0