I am trying to replace the data in my cPanel alises file to replace forwarded email addresses en masse.
The format I see in the file presently when I look at it in the CLI is:
emailaddresstoforward@example.com:
receivingemail1@example.com,receivingemail2@example.com,receivingemail3@example.com
emailaddresstoforward2@example.com:
receivingemail1@example.com,receivingemail2@example.com,receivingemail3@example.com
*: ":fail: No Such User Here"
I am using an array to create these as such:
$string = '';
$email = 'emailaddresstoforward@example.com';
$string .= "\n" . $email . ":\n";
foreach ($user AS $c) {
$user = get_userdata($c->ID);
$string .= $user->user_email . ",";
}
//remove trailing comma
$string = substr($string, 0, -1);
return $string;
This part seems to return fine at least when I view the data in the browser.
However, at the end I need to produce a few final lines outside of the array and that is where the trouble is.
$singleemail = "\nsingleemail@example.com:\nsinglereceipientl@example.com\n";
$finalcomment = "\*: \":fail: No Such User Here\"";
Then I put it all together with:
return $string . $singleemail . $finalcomment;
The problem is, the first part, the array prints out fine with the proper line breaks.
The single email and the final comment all print out on one line and appear to be ignoring the line breaks.
My questions are:
Am I doing something wrong with the use of \n? Or should I be using something else? What is the reason, they are working previously, but not on those final few lines?
Should I be using something else if I am going to print it to the forwarding/alias file?