How to echo user input within mail body - php

I'm working on php mailer and I've tried all possible means to echo out the user input within the mail body, but i keep getting an error. below is my code
$mail->isHTML(true);
$body="<p><center><img src='https://example.com/images/mail-icon.png'><br>Example</center></p>
<center><h3>You are welcome</h3></center><br>
<p>
$mail->='$_POST['fname']'

Answer for your question is very simple. So, I dont know how your form looks, but all you need to do is:
$body=$fname;
Perhaps, inside $body you can write also html message, as $body="<p>Dear,<br> You just received a message from:". $fname ."</p>";

Related

PHPMailer - Trying to set new line while sending emails

I've connected PHPMailer to my register system and once a user registers it auto-sends a email to the registered user, now I'm having a issue while attempting to set a new line while sending the email:
"Hello, ".$formvars['name']."<br>".
"Thank you for your registration with us and trusting us with your user account!"."<br>".
"If any problems arrise with logging into your account or using it, please adress this email."."<br>".
"\n".
"Kind Regards."."<br>".
"Auto-Bot!"."<br>";
I don't really see why it wouldn't make a new line properly, the \n or \r\n don't show in the email but also don't make a new line.
UPDATE:
Apologize for not providing enough code, the issue was that I called isHTML and tried to do that, I changed the lines to split up using
At a guess (because you didn't post your code), you're probably sending plain text as HTML, and HTML will ignore line breaks, so omit this line from your code:
$mail->isHTML();
If you want to use HTML, you can use HTML tags such as <p> and <br> to break up your text.

Change hyperlink when sending group mails

When sending a group mail about assigning to a newsletter, I need to create a hyperlink button which redirects to: example.com/action.php?id=11 ... email=<%email>
I need to change the <%email> area depending on the recipient's email...
I've done some research, but haven't come up with any solution.
Thanks for any response.
assign variable in code eg
$email = "someone#somewhere.com";
include the variable with the string eg.
echo "example.com/action.php?id=11&email=$email";
You can keep something like <%email> as placeholder text in mail body of each mail text in group mail and later you can replace this with your original email by using str_replace() function when you actually sending mail in your loop before sending mail.
provide complete code you are trying to do so we can help you more with it.

HTML in php mail function

I have a contact form on my website so users can send me an email but I have run into a problem.
I want to use an HTML link inside the email and I also want the content the user is sending to me to be formated how they would like it.... let me explain.
If a user sends this:
Hello World!
Isnt it a great Day?
without using headers to enable html, then it says formated like that when it reaches me.
If I use headers (MIME) to enable html, to also include a link in the email (which I would like to do), then it reaches me as:
Hello World!Isnt it a great Day?
How can I include html, and also keep the email formatted properly?
Thanks
And hopefully all this makes sense :S
Use nl2br on your message - http://php.net/manual/en/function.nl2br.php
It will replace all newlines with HTML <br>
$message = nl2br($message, false);
The second parameter *is_xhtml* is optional if you want to send an HTML email instead of XHTML

html form to edit php code

I'm working on a project that allows users to edit PHP code in PHP file.
I have a PHP page that uses the mail function to send emails. I want to allow the user to change the message sent out (in the mail function).
I know how to re-write over a file but how to edit it, I'm not sure...
So here's the mail function:
$name=$_POST['userName'];
$emaily=$_POST['userEmail'];
$email = "$sponsor_email";
$subject = "the subject";
$message = "This is the message I want the user to be able to edit.";
mail($email, $subject, $message, "From: $user-email");
Now I've got the $message var printed out on in the html form (so the users can see what will be changed but i don't know how I'd go about actually writing the code to change it on from submit.
Any ideas?
Thanks!
Sorry guys....
I didnt explain the situation properly.
The php file with the mail function will not be used to send an email from that form. All i want the form to do is edit the php file basically. I don't want to send the email with this form, this is for users to edit the mail function. Hope thats more clear...
On your editing page, just do something like below:
$message = file_get_contents("path to message file");
echo "<textarea id=\"message\">".$message."</textarea>";
Then you can edit whatever the contents of the file were.
Might be better though if you used a database, and sanitized the user input - rather than saving everything to a file.
Put the textarea in the form named "message", then do $message = $_POST['message'];
create a PHP that read what is in the PHP file that contains code to be edited then print it out in a HTML textarea then make another file that will write that modified code in the PHP file that has the code(to be modified). You can use google find how to read and write in a file.

php email html link, but just showing up as html code

I'm trying to e-mail a html table, that has links within it. But when I receive the e-mail, it just shows me the html code itself.
I'm using PHP pear to send the email.
I try constructing a string like so
$body = "<table>";
$body = $body . "<tr><td><a href='http://google.ca'>Google</a></td></tr>";
$body = $body . "</table>";
then e-mailing it, but when I receive the e-mail, it comes like this
<table><tr><td><a href='http://google.ca'>Google</a></td></tr></table>
Any suggestions? Thanks!
You'll want to ensure you are passing HTML to the setHTMLBody() function. If the problem continues, we'll need to see more of your PHP code.
It doesn't look like you're setting the Content or MIME-type for HTML email (which means its just being sent in plain text).
Check out this link for a guide on HTML email in PHP: http://articles.sitepoint.com/article/advanced-email-php

Categories