0

I am trying to send a mail with ajax and php

<script type="text/javascript">
    
      $(function() {
        $("#recibir").click(function() {
           var data = {
       
        email: $("#email").val(),
      
                };
                $.ajax({
                    
                    type: "POST",
                    url: "http://app.prabyc-proyectos.com/enviar-phpmailer.php",
                    data: data,
                    success: function(){
                        $('.success').fadeIn(1000);
                    }
                });
    
            return false;
        });
    });
            </script>

Here is the HTML form:

<form method="post" enctype="multipart/form-data" action="" id="myform" name="myform">
      
       <table>
        <tr>
            <td>Email:</td>
            <td><input type="text" name="email" value="" id="email"></td>
            <td><input type="submit" id="recibir" name="recibir" value="Recibir email"/></td>
        </tr>
    </table>
    
    </form>

and I have these errors

XMLHttpRequest cannot load http://app.prabyc-proyectos.com/enviar-phpmailer.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

POST http://www.app.prabyc-proyectos.com/enviar-phpmailer.php net::ERR_NAME_NOT_RESOLVED send

m.extend.ajax

(anonymous function) formulario-phpmailer.php

m.event.dispatch

r.handle

3
  • is that url on the same server as the script? Commented Jul 10, 2014 at 21:30
  • yeah is the same, when i send the mail directly from the action in the form works perfectly but not in the script! Commented Jul 10, 2014 at 21:33
  • What happens when you change the ajax call to: url: "/enviar-phpmailer.php",. If it's all on the same domain, that should get rid of the first error. Commented Jul 10, 2014 at 21:46

1 Answer 1

1

The problem is that the browser thinks that it's a cross origin request. I'm not sure what exactly is the problem, you have a url hardcoded in your ajax request statement. It probably is something very trivial, like a missing WWW, try adding that and see if it works ;)

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah if i add www solved the first problem. But no the second

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.