是的,今晚我受到精神上的挑战。 如果有人可以提供帮助,那就非常酷。
我只需要在' out'之后在返回消息的php字符串中添加换行符。
PHP文件
// CHANGE THE TWO LINES BELOW
$email_to = "m.wolf@me.com";
$email_subject = "message submission";
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$message = $_POST['message']; // required
$email_message = "Form details below.nn";
$email_message .= "Name: ".$name."n";
$email_message .= "Email: ".$email_from."n";
$email_message .= "Message: ".$message."n";
$headers = 'From: '.$email_from."rn".
'Reply-To: '.$email_from."rn" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
}
// return all our data to an AJAX call
echo json_encode($data);
JS FILE
scotchApp.controller('FormController',function($scope, $http) {
// creating a blank object to hold our form information.
//$scope will allow this to pass between controller and view
$scope.formData = {};
// submission message doesn't show when page loads
$scope.submission = false;
// Updated code thanks to Yotam
var param = function(data) {
var returnString = '';
for (d in data){
if (data.hasOwnProperty(d))
returnString += d + '=' + data[d] + '&';
}
// Remove last ampersand and return
return returnString.slice( 0, returnString.length - 1 );
};
$scope.submitForm = function() {
$http({
method : 'POST',
url : 'process.php',
data : param($scope.formData), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
})
.success(function(data) {
if (!data.success) {
// if not successful, bind errors to error variables
$scope.errorName = data.errors.name;
$scope.errorEmail = data.errors.email;
$scope.errorTextarea = data.errors.message;
$scope.submissionMessage = data.messageError;
$scope.submission = true; //shows the error message
} else {
// if successful, bind success message to message
$scope.submissionMessage = data.messageSuccess;
$scope.formData = {}; // form fields are emptied with this line
$scope.submission = true; //shows the success message
}
});
我似乎无法使其发挥作用。 我知道,入门级非常糟糕。
如果有帮助:我正在使用php / angular / bootstrap。 无论如何。谢谢。
答案 0 :(得分:1)
<?php
$data['messageSuccess'] = 'Thanks for reaching out'.PHP_EOL.' We will contact you shortly. ';
echo nl2br($data['messageSuccess']);
?>
或使用\ n:
<?php
$data['messageSuccess'] = "Thanks for reaching out.\n We will contact you shortly.";
echo nl2br($data['messageSuccess']);
?>
如果您没有启用错误报告,而且似乎没有,您可以这样做:
<?php
// Turn off error reporting
error_reporting(0);
// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Report all errors
error_reporting(E_ALL);
// Same as error_reporting(E_ALL);
ini_set("error_reporting", E_ALL);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>
答案 1 :(得分:0)
使用<br />
或\n
来强制使用&#34;一条新线。或者您可以将句子包装成<p>
标签,如下所示:
$data['messageSuccess'] = '<p>Thanks for reaching out.</p> <p>We will contact you shortly. </p>';