Style link in html email

Sending an email from a server isn’t quite as easy as sending it from a client. I know I can choose to send plain text or html, but I want to keep things as simple as possible. I have a link in the email that the user should click to reset their password. When I send the whole link, and check my gmail, it becomes a hyperlink automatically. My guess is that this isn’t the case in all email clients. What are my options for sending a link in plain text format? Is the only way to be sure to have a clickable link to use html? If I use html, what is the minimum markup I must have?

4 Answers 4

If you send your email in plain text, then your URL will be plain text. It’s plain text, you can’t dress it up.

If you send it as HTML, just use a simple anchor tag and use the URL as both the href and the text. That way if a mail client removes the link at least the user will still be able to copy/paste the url.

Another option rather than simply including urls inline in your text is to use a markdown-ish syntax that allows you to separate the two. For example, using citation-style link references (a la the way SO does it in this editor) could be done like so:

Hello, this is a plain email that links to a [cool page][1]. Sincerely, Joe [1]: http://foo.com/cool_page 

I’ve seen it done this way and it works well, especially if you have a lot of links.

Читайте также:  Java heap space outofmemoryerror maven

There is a syntax similar to angle-addr as defined in RFC2822 and mailto URL Schema defined in RFC2368.

RFC2396 mentions using angle brackets as delimiters around URI in text documents and protocol fields:

The angle-bracket «» and double-quote («) characters are excluded because they are often used as the delimiters around URI in text documents and protocol fields. The character «#» is excluded because it is used to delimit a URI from a fragment identifier in URI references (Section 4). The percent character «%» is excluded because it is used for the encoding of escaped characters.

Example derived from real-world usage:

From: alpha@beta.com To: theta@omega.com Content-Type: text/plain Some introduction text The text I want to display in this link The rest of my plain text message 

Источник

I’m just starting off with HTML / CSS and was having a little trouble formatting an email link embedded in a

tag. What sort of CSS selector could I use to access the element here? I’d like to be able to edit it as a link, hovered over, etc., so a selector using a:link or something like it would help. Thanks!

 

Contact Me

email: foo@bar.com

aim: deadunderdecor

3 Answers 3

Works great, I tried this earlier to no avail and then once again couldn’t get this to work after seeing your answer. I then remembered that I had changed the link in my head tag to a different style sheet in order to test something and never switched it back. Doh! Thanks a lot though.

Where would the :hover go in this case? EDIT: Nevermind, found out from another source that it goes after the right bracket.

@alex For some reason I can’t get the text-decoration:underline; to work. Should a[href^=»mailto:»] work? I’m using it on other anchors on the page and it works fine.

This works too, but I chose alex’s answer due to the fact that it’s more useful in general situations. Thanks!

would work but is more performance expensive and less general than merely using

CSS works by using each select (#content, a, etc.) in the declaration to get to more specific elements. By default, a selector that precedes another selector can have any number of elements in between it and what it precedes. The alternative I suggested would style any link that is inside of an element with an ID of content.

The solution Alex proposed is much more restrictive. Using «>» modifies the selection so that it doesn’t match any n-nested element and instead matches only elements that are immediate children of the selector to the left.

Because in the second instance, the P tag is no longer the immediate child of the #content element.

As far as CSS styling goes, you’ll want to use the :hover, :visited, and :active pseudo-classes to modify it’s appearance while the user is interacting with them.

#content a:hover < color: #ff0; >/* changes the color on hover */

There are a lot of good tutorials on the internet that explain this more fully. If you search for CSS anchor pseudo classes, you’ll get plenty of good answers.

Источник

Adding style to a php html email

I am wanting to send a newsletter type email, so the styling really matters for this. All of the videos I watched were just making html sheets, so I really didn’t get that. I want to style the content in my email. I have this right now:

$to = $newsletter_email; $subject = 'Thank you for subscribing'; $message = '    #email-wrap  

Hi,


Thank you.


Thank you,

Administration

'; $from = "newsletter@example.com"; //$Bcc = "example@example.com"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: ' .$to. "\r\n"; $headers .= 'From: ' .$from. "\r\n"; // $headers .= 'Bcc: '.$Bcc. "\r\n"; // Send the email mail($to,$subject,$message,$headers);

I have tried taking out the style from this message variable and turning this file into a html styled file, outside of the php:

etc. The email actually sends, but I cannot figure out how to add style to this. What am I doing wrong??

 $email_from = "newsletter@example.com"; $full_name = 'Company Name'; //$from_mail = $full_name.''; $from = $from_mail; //$from = "newsletter@example.com"; //$Bcc = "example@example.com"; // To send HTML mail, the Content-type header must be set $headers .= "From: ".$full_name." \r\n"; and $headers .= "Return-Path: ".$full_name." \r\n"; /*$headers = "" . "Reply-To:" . $from . "\r\n" . "X-Mailer: PHP/" . phpversion();*/ $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: ' .$to. "\r\n"; $headers .= 'From: ' .$from_email. "\r\n"; // $headers .= 'Bcc: '.$Bcc. "\r\n"; // Send the email mail($to,$subject,$message,$headers); 

Источник

Adding css in html that will be sent to an email

I have created a method that will send an email with information to customers. However, the email looks awful cus there is no style to it. I can’t apply the style to the email for some reason. I have tried to google it, and there is a lot on how to solve this in code behind, but that’s not my issue. I must place the css code in the Html body, since it must be displayed for the client when he opens the email. So my question is, how do I add css to the html code above? I have tried doing:

and this does not work Any help on how to solve this is appreciated. Below some of my code. I have shortened it, for readability.

string HtmlBody = @" 

Faktura


Navn:
Adresse:
Postnr:
Land:
Tlf:  
Mail:  

Dato



Fakturanr: %fakturanr%
Ordrenr: %Ordrenr%
";
MailMessage mailMsg = new MailMessage(); mailMsg.IsBodyHtml = true; mailMsg.Priority = MailPriority.Normal; var smtpValues = GetSmtpValues(); var smtpCredentials = GetNetworkCredentials(); SmtpClient smptClient = new SmtpClient(smtpValues.Key, smtpValues.Value); smptClient.EnableSsl = true; smptClient.Credentials = new NetworkCredential(smtpCredentials.Key, smtpCredentials.Value); //Send mail smptClient.Send(mailMsg); 

Источник

Sending an email from a server isn’t quite as easy as sending it from a client. I know I can choose to send plain text or html, but I want to keep things as simple as possible. I have a link in the email that the user should click to reset their password. When I send the whole link, and check my gmail, it becomes a hyperlink automatically. My guess is that this isn’t the case in all email clients. What are my options for sending a link in plain text format? Is the only way to be sure to have a clickable link to use html? If I use html, what is the minimum markup I must have?

4 Answers 4

If you send your email in plain text, then your URL will be plain text. It’s plain text, you can’t dress it up.

If you send it as HTML, just use a simple anchor tag and use the URL as both the href and the text. That way if a mail client removes the link at least the user will still be able to copy/paste the url.

Another option rather than simply including urls inline in your text is to use a markdown-ish syntax that allows you to separate the two. For example, using citation-style link references (a la the way SO does it in this editor) could be done like so:

Hello, this is a plain email that links to a [cool page][1]. Sincerely, Joe [1]: http://foo.com/cool_page 

I’ve seen it done this way and it works well, especially if you have a lot of links.

There is a syntax similar to angle-addr as defined in RFC2822 and mailto URL Schema defined in RFC2368.

RFC2396 mentions using angle brackets as delimiters around URI in text documents and protocol fields:

The angle-bracket «» and double-quote («) characters are excluded because they are often used as the delimiters around URI in text documents and protocol fields. The character «#» is excluded because it is used to delimit a URI from a fragment identifier in URI references (Section 4). The percent character «%» is excluded because it is used for the encoding of escaped characters.

Example derived from real-world usage:

From: alpha@beta.com To: theta@omega.com Content-Type: text/plain Some introduction text The text I want to display in this link The rest of my plain text message 

Источник

Оцените статью