00stuff Posted July 14, 2011 Share Posted July 14, 2011 I"m trying to write this variable on a php page with fwrite() but can't pass the \n in the mail() message. It removes the "\" and a letter n comes out. Can someone help please? My Code: $stringData2 = <<<EOF <?php \$name_first = \$_POST['name_first']; \$name_last = \$_POST['name_last']; \$phone = \$_POST['phone']; \$email = \$_POST['email']; \$to = "$receive_email"; \$subject = "Registration to $company_name"; \$message = "First Name: \$name_first \n Last Name: \$name_last \n Phone: \$phone \n Email: \$email"; \$from = "$receive_email"; \$headers = "From: \$from"; mail(\$to,\$subject,\$message,\$headers); echo "Mail Sent. Click <a href='register.php'>here</a> to go back!"; ?> EOF; How can I make sure the "\n" stays there? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 14, 2011 Share Posted July 14, 2011 have you tried fwrite($fh, "e-mail\n"); Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 14, 2011 Share Posted July 14, 2011 I have no idea what you are trying to do, but I'm pretty sure you are going about it the wrong way. You are putting PHP code into a variable for what purpose? Anyway, the problem is that you are escaping the "n" in the creation of that variable. But, you need the "n" escaped in the code that is eventually created. But, your results don't make sense to me. You are using the heredoc method of creating the string and the escape codes should be interpreted. Therefore, I would expect that the result of $stringData2 would include a literal linefeed (i.e. line break) so your code when written to a page would look something like $message = "First Name: $name_first Last Name: $name_last Phone: $phone Email: $email"; It doesn't make sense to me that you would get an "n" character. But, to get the "\n" to be in the resulting variable you would need to escape the backslash by using "\\n". Then the variable is created with "\n". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.