0

I have a PHP function mail function and i'm using an ajax post function to send the data to the server, the ajax seem to be working just fine, as it responses to the server and echo bunch of testing, here is my ajax call:

$j.ajax({
                type: 'POST',
                url: '../../../handleForm.php',
                crossDomain: true,
                beforeSend:function(){
                    $j("#loading").show();
                },
                success:function(res){
                    console.log(res);
                    // alert("good");
                    console.log(price);
                    window.location = "../../../thank-you"
                },
                error:function(){
                    alert("failed");
                },
                data: {name:name, email:email, phone:phone, qty:qty,product:product,price:price,company:company,selected:selected,currency:currency,note:note },
                complete:function(){
                    window.location = "../../../thank-you"
                    $j("#loading").hide();
                }
            });

console log out put the following:

clicked
handleForm.js:72 sent
handleForm.js:86 email sent client@gmail.com and to mail@mydomain.co.il
handleForm.js:88 123

<?php

if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['qty']) && isset($_POST['phone']) && isset($_POST['product']) && isset($_POST['price']) && isset($_POST['selected']) && isset($_POST['currency']) ){

    $to = 'mail@mydomain.co.il';
    $subject = 'הצעת מחיר מלקוח ' .$_POST['name'];

    $subjectC = 'הצעת מחיר ללקוח ' .$_POST['name'];

    $message = '<html><body>'
    $message .= '<p style="direction: rtl;text-align: right">';
    $message .= 'שם :'.$_POST['name'].'<br />';
    $message .= 'אימייל :'.$_POST['email'].'<br />';
    $message .= 'טלפון :'.$_POST['phone'].'<br />';
    $message .= 'מוצר :'.$_POST['product'].'<br />';
    $message .= 'כמות :'.$_POST['qty'].'<br />';
    $message .= 'מחיר מוצע :'.$_POST['price'].'<br />';
    $message .= 'שם חברה :'.$_POST['company'].'<br />';
    $message .= 'מטרת ההצעה :'.$_POST['selected'].'<br />';
    $message .= 'סוג מטבע :'.$_POST['currency'].'<br />';
    $message .= 'הערה :'.$_POST['note'].'<br />';
    $message .= "</p>";
    $message .= "</body></html>";

    $messageC = '<html><body>';
    $messageC .= '<p style="direction: rtl;text-align: right">';
    $messageC .= 'שלום, '.$_POST['name'].'<br />';
    $messageC .= 'תודה שפנית אלינו, אנחנו עושים את מירב המאמצים להיענות לבקשתך בהקדם, להלן פרטי בקשתך:'.'<br />';
    $messageC .= '<p style="direction: rtl;text-align: right">';
    $messageC .= 'שם :'.$_POST['name'].'<br />';
    $messageC .= 'אימייל :'.$_POST['email'].'<br />';
    $messageC .= 'טלפון :'.$_POST['phone'].'<br />';
    $messageC .= 'מוצר :'.$_POST['product'].'<br />';
    $messageC .= 'כמות :'.$_POST['qty'].'<br />';
    $messageC .= 'מחיר מוצע :'.$_POST['price'].'<br />';
    $messageC .= 'שם חברה :'.$_POST['company'].'<br />';
    $messageC .= 'מטרת ההצעה :'.$_POST['selected'].'<br />';
    $messageC .= 'סוג מטבע :'.$_POST['currency'].'<br />';
    $messageC .= 'הערה :'.$_POST['note'].'<br />';
    $messageC .= "</p>";
    $messageC .= "</body></html>";

    $hedears = 'From:mail@mydoamin.co.il'. "\r\n";
    $headers .= 'Reply-To:mail@mydoamin.co.il'. "\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-Type: text/html; charset=UTF-8'. "\r\n";
    $headers .= 'X-Mailer: PHP/' . phpversion();


    $headersC = 'From:mail@mydoamin.co.il'. "\r\n";
    $headersC .= 'Reply-To:mail@mydoamin.co.il'. "\r\n";
    $headersC .= 'MIME-Version: 1.0' . "\r\n";
    $headersC .= 'Content-Type: text/html; charset=UTF-8'. "\r\n";
    $headersC .= 'X-Mailer: PHP/' . phpversion();

    //send to client
    mail($_POST['email'],'title',$messageC,$headersC);

    mail('mail@mydoamin.co.il','title',$message,$headers);

    echo "email sent " . $_POST['email'] . " and to " . $to;

}

?>

but still the email are not getting through, and neither the client nor the domain are getting those email.

Boaz Hoch
  • 1,219
  • 1
  • 12
  • 36
  • try to find error by error_reporting_all then only solution can provided. – Alive to die - Anant Apr 04 '15 at 11:31
  • Please check the response of the mail() function. It must be returning a false indicating a mail sending failure. That is usually caused by an improper SMTP configuration. Try this SO thread for a possible solution, http://stackoverflow.com/questions/8384882/how-to-know-if-php-mail-failed – Domain Apr 04 '15 at 11:32
  • **Tip:** *`isset()`* accepts multiple parameters, so you can use this for a cleanest code: *`isset($_POST['name'], $_POST['email'], $_POST['qty'], $_POST['phone'], $_POST['product'], $_POST['price'], $_POST['selected'], $_POST['currency'])`* – Cliff Burton Apr 04 '15 at 11:43
  • i have checked if the mail function is false or true, it seems to be true. – Boaz Hoch Apr 04 '15 at 19:58

0 Answers0