Wp_mail的WordPress 500错误

时间:2017-10-25 14:08:34

标签: php angularjs wordpress email

我试图将数据从AngularJS发送到PHP文件并使用PHP发送带有wp_mail的电子邮件,但我得到500错误,我似乎无法弄清楚我哪里出错了。我似乎正在以正确的格式将数据发送到PHP文件,但我只是得到错误响应。

AngularJS Call

$scope.sendEmail = function() {
            if ($scope.resultsTitle) {
                $scope.resultsTitle = $scope.resultsTitle;
            }
            else if ($scope.resultsTitle == "") {
                $scope.resultsTitle = "Survey Not Completed";
            }
              $scope.userData = {
                "userEmail": $scope.email,
                "todaysDate": $scope.date,
                "timeNow": $scope.time,
                "question1": $scope.question1Answer.toString(),
                "question2": $scope.question2Answer.toString(),
                "question3": $scope.question3Answer.toString(),
                "question4": $scope.question4Answer.toString(),
                "question5": $scope.question5Answer.toString(),
                "question6": $scope.question6Answer.toString(),
                "question7": $scope.question7Answer.toString(),
                "question8": $scope.question8Answer.toString(),
                "question9": $scope.question9Answer.toString(),
                "question10": $scope.question10Answer.toString(),
                "endResult": $scope.resultsTitle
              };
              $log.info($scope.userData);


                $http({
                      method: 'POST',
                      url: 'mailer.php',
                      data: $scope.userData
                  })
                  .then(function successCallback(response) {
                            $log.log("Sent to PHP file!");
                            $log.log(response);
                    }, function errorCallback(response) {
                            $log.log("Data not sent to the php file!")
                            $log.warn(response);
                    });
        };

PHP Mailer文件:

<?php
 $postdata = file_get_contents("php://input");
    $request = json_decode($postdata);
    $user_email = $request->userEmail;
    $todays_date = $request->todaysDate;
    $time = $request->timeNow;
    $question1 = $request->question1;
    $question2 = $request->question2;
    $question3 = $request->question3;
    $question4 = $request->question4;
    $question5 = $request->question5;
    $question6 = $request->question6;
    $question7 = $request->question7;
    $question8 = $request->question8;
    $question9 = $request->question9;
    $question10 = $request->question10;
    $endResult = $request->endResult;


$message = "
    <html>
        <head>
            <title>The Title</title>
        </head>
        <body>
            <p>Thank you.</p>
            <table>
                <tr>
                    <th>Your Email</th>
                    <th>Today's Date</th>
                    <th>The Current Time</th>
                    <th>Question 1</th>
                    <th>Question 2</th>
                    <th>Question 3</th>
                    <th>Question 4</th>
                    <th>Question 5</th>
                    <th>Question 6</th>
                    <th>Question 7</th>
                    <th>Question 8</th>
                    <th>Question 9</th>
                    <th>Question 10</th>
                    <th>End Decision</th>
                </tr>
                <tr>
                    <td>$user_email</td>
                    <td>$todays_date</td>
                    <td>$time</td>
                    <td>$question1</td>
                    <td>$question2</td>
                    <td>$question3</td>
                    <td>$question4</td>
                    <td>$question5</td>
                    <td>$question6</td>
                    <td>$question7</td>
                    <td>$question8</td>
                    <td>$question9</td>
                    <td>$question10</td>
                    <td>$endResult</td>
                </tr>
            </table>
        </body>
    </html>
";

    echo ($user_email, 'The Subject', $message);
    return wp_mail($user_email, 'The Subject', $message);

?>

1 个答案:

答案 0 :(得分:0)

所有

解决方案最终在邮件中调整:

Changed return wp_mail to wp_mail
Deleted echo wp_mail

Added $parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' ); to the top of the file