string - PHP Response line break


Yes, I am mentally challenged tonight. If anyone could help, that'd be very cool.

I just need to add a line break to the php string of a return message after the 'out'.


  $email_to = "[email protected]";
  $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);


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() {
            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 =;
                    $scope.errorEmail =;
                    $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

I just can't seem to make it work. terribly entry level, I know.

If it helps: I am using php/angular/bootstrap. Anyway. thanks.




One way would be using PHP_EOL constant and nl2br function:

$data['messageSuccess'] = 'Thanks for reaching out'.PHP_EOL.' We will contact you shortly. ';
echo nl2br($data['messageSuccess']);

or using \n :

 $data['messageSuccess'] = "Thanks for reaching out.\n We will contact you shortly.";
echo nl2br($data['messageSuccess']);

If you don't have error reporting enabled, and it seems you don't, you can do it like this:

// Turn off error reporting

// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Report all errors

// Same as error_reporting(E_ALL);
ini_set("error_reporting", E_ALL);

// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);



Use<br /> or\n to "force" a new line. Or you can wrap your sentence into<p> tags like this:

$data['messageSuccess'] = '<p>Thanks for reaching out.</p> <p>We will contact you shortly. </p>';

People are also looking for solutions to the problem: How to display php error like Codeigniter?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.