0

I am trying to send an email inside a php script using PHPmailer, so I need the PHPmailer class which I included at the top of my page, I am 100% sure everything is correctly uploaded on my server.

My structure is like this:

root
 - includes/addreviewscript.php
 - phpMailer/class.phpmailer.php

I post data to that script using below jQuery ajax code:

  // Post review
  $("body").on("click",".add_review",function(){
    event.preventDefault();
    $reviewform = $(".addreview").serializeArray();
    url = 'includes/addreviewscript.php';

    var posting = $.post( url, { reviewarray: $reviewform} );

    posting.done(function( data ) {
      var content = $( $.parseHTML(data) );
      $('[name="beoordeling"]').hide();
      $('[name="submitreview"]').hide();
      $('.beoordeeltekst').hide();
      $( ".reviewresponse" ).empty().append( content ).slideDown();
    });
  });

That works, but in my addreviewscript.php I then add this to the top:

include '../phpMailer/class.phpmailer.php';

And further down I add:

$mail = new PHPMailer;
$mail->From = 'info@mymail.nl';
$mail->FromName = 'website';
$mail->addAddress('twan@mymail.nl');     // Add a recipient
$mail->isHTML(true);           // Set email format to HTML
$mail->Subject = 'Er is een review geplaatst op website';
$texts = 'Hier komt de reviewtekst';
$mail->send();

But no mail is send and no error_log is generated. What could be the issue?

twan
  • 2,017
  • 8
  • 22
  • 59
  • Have you looked in the network console to see what the AJAX response is, or what the HTTP code returned is? – Mitya Feb 15 '19 at 11:44
  • Looks like you did not properly configured php mailer.. I don't see you loading the smtp class.. but looks like u sending mails with smtp – Masivuye Cokile Feb 15 '19 at 11:45
  • @Utkanos Yes the call went through correctly and I echo a message that the review has been added, that message is shown in my response. – twan Feb 15 '19 at 11:45
  • @MasivuyeCokile I have the same script somewhere else that does not use AJAX, and it works. So it should be fine. – twan Feb 15 '19 at 11:46
  • Hmm. Well as long as the variables are being received by the server script, then this has nothing to do with AJAX. That's simply the means of invoking the mailer script. To confirm, run `print_r($_REQUEST)` to check you're getting what you think you should be. – Mitya Feb 15 '19 at 11:46
  • It looks like you're not using the current version of PHPMailer. You should be using version 6, if possible. – Martin Feb 15 '19 at 11:48

0 Answers0