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

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

Related

How to echo user input within mail body

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

Where do I format my html email?

So I have designed a website that Ill be hosting very soon. Everything works including forms. However, When a user sends me emails through the form, the email formatting is very ugly.I want to design my emails, something like this:
https://cdn.tutsplus.com/webdesign/uploads/2013/06/21.png
So when I send an email to my client, it should somewhat look attractive like above.
My question is, where do I code the design of the HTML email? Do I do that in my index.html, where my website content is there? But that doesn't make sense?
Do I create a new HTML file and do the code there? and how do i do it?
Thanks in advance
From a plain ugly mail moving to the "right formatted" template mails is a big jump.
You need to tell what you are using to send the mail. Are you using any frameworks or is it just PHP?
To send mails in HTML format, use the below as part of the headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Are you already sending mails in HTML Format and just need help on formatting the HTML? Just remember that most of the email clients and email providers don't support external css files. Gmail even removes the CSS Styles at the head of the HTML. Your safest place for CSS styles will be inline using "Style" tag.
For the fancy formatting, I think the safe way to go is to use Tables (and nested tables if need be) most of the email clients and email providers remove the Div tags also.
If you are using PHPMailer then you can save the HTML code into a variable and assign it to the Body like given below:
$mail->Body = "<!-- your html code goes here -->;
As was mentioned by Els Den Lep, there is no way to guarantee that your mail will appear in the format you want in all the email providers / client. However, if you use a combination of Tables, inline CSS you can be fairly sure of a robust display (very close to what you want).
An inelegant hack will be to convert your HTML as an image and use utilities like GIMP or Photoshop to convert it into an HTML using the slice option. This can be especially useful if you are having a large image where you need to give links to specific areas of the image.
Supposing that the file that handles the sending of your email is called sendmail.php, you can do the styling in your sendmail.php as inline css like so:
$message = 'Contact form.<br />';
$message .= 'Subject:<br />';
$message .= "<h1 style=\"color:blue;margin-left:30px;\">This is a heading.</h1><br />";

PHP prepare MAILTO with HTML

Im looking for a solution, to prepare a complete email for opening with a mail client
PHP is used for generating the link.
Here is the usefull part of my code.
$body = str_repalace('&amp','%26',$body);
$mailtarget = "mailto:".$adress."?cc=".$ccs."&Subject=".rawurlencode($subject)."&Body=".$body.
header("Location = $mailtarget");
This solution works fine, unless i use html in the mail, which is necessary (<br>,<hr>, <table>.
If used HTML sometimes nothing gets in Body, and sometimes just a part of the text.
When I mail the HTML with sendmail.exe, it works perfect. But this is not an option, since its required to add attachments manually to the mail.
Is there any way, to get this properly to work?
It's not possible to include HTML in body's mailto.
You can try to url_encode your HTML and set it as body in your mailto link, but it has a lot of risks of not working in many email clients.
From this answer, it's even defined in the RFC 2368 :
The special hname "body" indicates that the associated hvalue is the
body of the message. The "body" hname should contain the content for
the first text/plain body part of the message. The mailto URL is
primarily intended for generation of short text messages that are
actually the content of automatic processing (such as "subscribe"
messages for mailing lists), not general MIME bodies.
Try: &Body=".urlencode($body);
Use rawurlencode function to insert carriage return :
<?php
$body = '
First line
Second line';
header("location: mailto:emailadresse#domain.com?subject=Hello&body=".rawurlencode($body));
?>

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.

Categories