php - postmark email sends from command line but not AJAX even though AJAX returning 200? -


i sending emails postmark through terminal , works. want client website no maintenance , happy times.

curl "https://api.postmarkapp.com/email" \   -x post \   -h "accept: application/json" \   -h "content-type: application/json" \   -h "x-postmark-server-token: 555-5555-555" \   -d "{from: 'info@pythondevhouse.com', to: 'cchilder@mail.usf.edu', subject: 'hello postmark', htmlbody: '<strong>hello</strong> dear postmark user.'}" 

i adapted ajax call so:

$('.new-email-button').click(function() {      var fromemail = $('.email').val();     console.log('email');     console.log(fromemail);     var message = $('.email-message').val();     console.log(message);     var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-za-z\-0-9]+\.)+[a-za-z]{2,}))$/;     if (re.test(fromemail)) {         $.ajax({             type: "post",             url: "https://api.postmarkapp.com/email",             data: {               "from": "info@pythondevhouse.com",               "to": "cchilder@mail.usf.edu",               "cc": "copied@example.com",               "bcc": "blank-copied@example.com",               "subject": "test",               "tag": "invitation",               "textbody": message,               "replyto": fromemail,               "headers": [                 {                  "name": "x-postmark-server-token",                 "value": "ba7663a2-19ba-4a42-bf69-5b4485fcab6f"                   }               ],               "trackopens": true             },             contenttype: "application/json",             accepts: {                 text: "application/json"             }             }).done(function(response) {              alert(response);              if (response[0].status == 'rejected'){                alert("i'm sorry, email form isn't working.\n\nplease email info@pythondevhouse.com\nor call 813-555-5555");              }              else{                alert("sent successfully! thank you, contact soon");                console.log(response); // am.              }              if(response[0].status === "sent") {                $('.email').val('');                $('.email-message').val('');              }            });       } else {         alert("invalid email address");       } }); 

terminal send works immediately, ajax on site getting 200 not sending. can see error here (this local machine):

enter image description here

following fixes suggested fail:

    $.ajax({         type: "post",         url: "https://api.postmarkapp.com/email",         headers: {             "access-control-allow-origin": "http://codyc4321.github.io",         }         ... 

adding allow makes entire function silently fail, , no longer email request, nor error, seems make no sense. remove header , error saying didn't give thing gave it! this, job interview or dating?! gave asked for. remove "access-control-allow-origin" header , get:

enter image description here

please me send email based on error:

enter image description here

thank you


Comments