0

I have two different websites (www.kynero.nl and www.hondenkunstjes.nl). I have added a contact form on both websites. These forms are made of the same template.

The forms are handled by a php-file that simply emails the contents to me. The code of this php_file is below.

On both websites i get to the page 'bedankt.html' after filling in the form, which means the script is running correctly.

However, on the site www.hondenkunstjes.nl the mail is actually sent, on the site www.kynero.nl i do not receive an email when the form is sent.

What am i doing wrong here? Any ideas are welcome!

UPDATE: based on the answer of cjs1978 i decided to implement PHPMailer. However, with the code below, the page returns a white screen. What am i doing wrong here?

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer;
use PHPMailer\Exception;

//Load Composer's autoloader
//require 'vendor/autoload.php';

$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Message = $_POST['Message'];

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';                     // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '***@gmail.com';                 // SMTP username
    $mail->Password = '***';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom($email, $name);
    $mail->addAddress('***@gmail.com');     // Add a recipient
    $mail->addReplyTo($email, $name);

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Aanvraag via ***';
    $mail->Body    = " Naam: $Name \n Bericht: $Message";

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
Jaap
  • 57
  • 7
  • It's most likely something outside of the code causing this – John Conde May 31 '18 at 20:06
  • There could be more than one reason for this - server setup, php.ini settings... Have you considered using PHPmailer (https://github.com/PHPMailer/PHPMailer), it's stable, easier to debug and has more options for sending mail. – cjs1978 May 31 '18 at 20:08
  • Are both website hosted on the same server, its probably an issue with the mail configuration, also be carefull about [mail() headers injection](https://www.acunetix.com/blog/articles/email-header-injection/)! As @cjs1978 said you should probably use a library for this. – Korri May 31 '18 at 20:16

0 Answers0