Send HTML in email via PHP
It is pretty simple. Leave the images on the server and send the PHP + CSS to them...
$to = 'bob@example.com';
$subject = 'Website Change Request';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = '<p><strong>This is strong text</strong> while this is not.</p>';
mail($to, $subject, $message, $headers);
It is this line that tells the mailer and the recipient that the email contains (hopefully) well-formed HTML that it will need to interpret:
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
Here is the link I got the information from... (link)
You will need security though...
Send HTML emails with Python
From Python v2.7.14 documentation - 18.1.11. email: Examples:
Here’s an example of how to create an HTML message with an alternative plain text version:
#! /usr/bin/python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# me == my email address
# you == recipient's email address
me = "my@email.com"
you = "your@email.com"
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link"
msg['From'] = me
msg['To'] = you
# Create the body of the message (a plain-text and an HTML version).
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"
html = """\
<html>
<head></head>
<body>
<p>Hi!<br>
How are you?<br>
Here is the <a href="http://www.python.org">link</a> you wanted.
</p>
</body>
</html>
"""
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
# Send the message via local SMTP server.
s = smtplib.SMTP('localhost')
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(me, you, msg.as_string())
s.quit()
What's a quick, easy way to send HTML emails to myself to test them?
A Test Mail Server Tool can help with that -if you just need to receive and view any emails sent by your application.
How to send html email through Azure Logic App and Outlook
Open the "Send Email" task and click on Advanced Options. There is a "Is HTML" setting under there.
How to send HTML email using R
This is possible, cf https://stackoverflow.com/a/21930556/448145
Just add:
msg <- mime_part(message)
msg[["headers"]][["Content-Type"]] <- "text/html"
sendmail(from, to, subject, msg = msg, ...)
How to Send A Complicated Email with Flutter Mailer Package
There are 2 aspects to this question.
- How to set the stripo html.
- How to adapt an html template. (Modify the content to change parts of the template)
To set the template simply do:
message.html =
'''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
[... copy the complete template here ...]
</html>'''
Three quotes ('''
) instead of one quote ('
) allows text to span multiple lines.
To keep your code clean, you might want to create a new dart file: mail-template.dart
and assign the html-template to a variable. Then include this file and assign the variable.
To replace parts of the template I would use .replaceAll
on the template.
var nameFromSomeInput = 'Jane Doe';
var yourHtmlTemplate = '<html>Dear {{NAME}}</html>';
message.html = yourHtmlTemplate.replaceAll('{{NAME}}', nameFromSomeInput);
Note that replaceAll
is easy and doesn't depend on any additional libraries. It is however slow. Especially if you replace multiple values by calling replaceAll
multiple times.
Consider a template engine like: jinja in such cases.
How to send HTML in email using Django?
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
def send_emails(request):
merge_data = {
'greetings': "hello"
}
html_body = render_to_string("email-templates.html", merge_data)
message = EmailMultiAlternatives(
subject='Django HTML Email',
body="mail testing",
from_email='xyz@abc.com',
to=['wxyz1@abc.com']
)
message.attach_alternative(html_body, "text/html")
message.send(fail_silently=False)
Related Topics
Converting an Array of Objects to an Array of Their Primitive Types
Java 8 Date and Time: Parse Iso 8601 String Without Colon in Offset
Difference Between List, List<>, List<T>, List<E>, and List<Object>
Declaring an Unsigned Int in Java
Compile-Time Constants and Variables
Reverse Each Individual Word of "Hello World" String with Java
Missing Return Statement for If/Else Statement
Java Webservice Client (Best Way)
Java: Why Is the Date Constructor Deprecated, and What Do I Use Instead
Platform Independent Paths in Java
Why Shouldn't You Extend Jframe and Other Components
Is the Buildsessionfactory() Configuration Method Deprecated in Hibernate
How to Check If My String Is Equal to Null
Import Package.* VS Import Package.Specifictype
Is Jdk "Upward" or "Backward" Compatible
What Is the Point of Setters and Getters in Java
How to Fix Ambiguous Type on Method Reference (Tostring of an Integer)