In PHP
That way you can really have a lot of control.
By using PHP PEAR you could do something like this:
$_SMTP = array(
"host" => "ssl://smtp.gmail.com",
"username" => "[email protected]",
"password" => "password123",
"port" => "465",
"auth" => true
);
include_once('PEAR.php');
include_once('Mail.php');
include_once('Mail/mime.php');
$mime = new Mail_mime();
$mime->_build_params['html_charset']='UTF-8';
$mime->_build_params['text_charset']='UTF-8';
$mime->_build_params['head_charset']='UTF-8';
$mime->_build_params['head_encoding']='base64';
$mime->setTXTBody("Plaintext message");
$mime->setHTMLBody("<b>HTML message</b>");
$hdrs = array(
'From' => '"Me" <[email protected]>',
'Subject' => "Test message",
'To' => '"Example" <[email protected]>'
);
$body = $mime->get();
$headers = $mime->headers($hdrs);
$mail =& Mail::factory('smtp', $_SMTP);
$result = $mail->send('"Example" <[email protected]>', $headers, $body);
print_r($result);
In fact, you can even print_r($headers); to give you some impression of them even before you send.
There are more options to tinker with this, so you might want to research this.
In python
It is also possible to do so in python, using the base libraries email and smtplib as described here
The main idea is to set the header, and you can set the value in plain text using :
msg = MIMEText("text of the mail",'plain')
msg['Subject'] = "=?utf-8?b?Y2Fmw6k=?="
or to generate a proper format from a text :
msg = MIMEText("text of the mail",'plain')
msg['Subject'] = Header("café","utf8")