Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Adithya1997's avatar

Email function not working

I recently created a laravel application. In that, there was a section enquiry which deals with getting enquiries from users and sending it to the given email. The function works correctly when deployed in local host but shows alert when deployed in server system. What can the reason be?

0 likes
10 replies
Cronix's avatar

How are you sending the mail? Are you using something like mailgun or what service are you using to send it? Did you update your .env settings for mail?

Snapey's avatar

what alert, where? you are not giving much away...

Adithya1997's avatar
var sentMail = function(name,email,message){
     var data2 = {"name":name,"email":email,"message":message};
     var postData = {"data":data2};
     $.ajax({
      type: "POST",
      crossDomain: true,
      data : data2,
      url: '/MaxloreSite/sentmail/sent.mail.php',
      success: function(result){
            if(JSON.stringify(result)=='"Message successfully sent!"'){
                $("#mydiv").hide();
                swal({
                    text:"Message sent successfully !!",
                    type: "success",
                    timer: 3000
                });
                $("#from1")[0].reset();
            }else{
                $("#mydiv").hide();
                swal({
                    text: "Error please try again !!",
                    type: "error",
                    timer: 3000
                    });
            }
      },
      error:function(result){
        $("#mydiv").hide();
        swal({
            text: "Error please try again !!",
            type: "error",
            timer: 3000
            });
          //alert(JSON.stringify(result));
      },
      beforeSend: function (xhr) {
       xhr.setRequestHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With');
      }
     });

}
Snapey's avatar

does that look readable to you?

please format your code

what is the php code? Is that laravel or some function you found somewhere?

Adithya1997's avatar

The code is a php code which is stored as a js file which is used to send an enquiry from the user side and it is received by the server.

Cronix's avatar

The javascript you are showing isn't php, doesn't contain any php, and it isn't sending an email. It might be triggering something that sends an email, but it itself isn't. The problem is probably in the `url: '/MaxloreSite/sentmail/sent.mail.php', file that the ajax request is being sent to.

Adithya1997's avatar

Can that php file be seen through inspect in google chrome?

Cronix's avatar

Just the url to it (since it's in your javascript), but no, you can't see the "contents" of it.

Adithya1997's avatar

OK. Then i can send the contents after around 11 hours only. Since I am not in office now.

Cronix's avatar

Is this even a laravel app? Normally, you don't post directly to a .php file, you post to a url that laravel routes to a controller. So far, you've shown nothing related to laravel?

Please or to participate in this conversation.