Jump to content

I'm writing a variable to a file with fwrite() but can't pass \n on mail() messg


00stuff

Recommended Posts

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?

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.