简体   繁体   中英

how to send email to godaddy hosted emailid using PHP and angularjs

I'm developing an ionic app, in which i need to send feedback to the specific email id, for that I,m using php as server side code, I tried PHPMailer, and php mail() function but unfortunatly nothing works... please help me solve this problem...

here is my service.js

sendEmailFunction: function(feedbackUser) {
            var data = {    
                            userEmail: feedbackUser.userEmail,
                            feedback: feedbackUser.feedback,
                            sendToMail: feedbackUser.sendToMail };
            var link = 'http://localhost/endpoints/sendEmail.php';
            return $http.post(link, data);
        }

here is controller.js

$scope.sendFeedback = function(feedbackUser) {
                AllServices.sendEmailFunction(feedbackUser)
                .then(function(response) {
                    console.log("success");
                })
                .catch(function(error) {
                    console.log(error);
                });   
    };

here is .php file

<?php
    include ("connection.php");

    $data = json_decode(file_get_contents("php://input"));

    $userEmail = $data->userEmail;
    $feedback = $data->feedback;
    $sendToMail = $data->sendToMail;
    $resp = array();

        $to      = $sendToMail;
        $subject = "test anjali";
        $message   = $feedback;
        $Header = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $Header .= 'From: Customer <$userEmail>' . "\r\n";
        ini_set('SMTP', "relay-hosting.secureserver.net");
        ini_set('smtp_port', "25");

    if(mail($to, $subject, $message, $Header)) {
        $resp['STATUS'] = '_SUCCESS';
    }

    else {
        $resp['STATUS'] = '_FAIL';
    }

    echo json_encode($resp);
?>

I'm not getting why m not getting an email in godaddy hosted email service.. please help me....

Because you're not concatenating the $userEmail. Replace this:

$Header .= 'From: Customer <$userEmail>' . "\\r\\n";

With this:

$Header .= "From: Customer <".$userEmail.">" . "\\r\\n";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM