What to include in email headers using php mail ()?
When I want to send an email, my codes look like this:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: me@localhost' . "\r\n";
// Email Variables
$toUser = 'you@something';
$subject = "Testing";
$body = '<html><head><title></title></head><body>
This is my picture <img src="http://domain.com/me.jpg">';
if(mail($toUser,$subject,$body,$headers)){
echo "Email sent!!";
}
Here are my questions:
- Should I include tags
<html>, <head>, <title>...
? - Can a stylesheet be used? For example
<div style="...">
,? - I tested sending an email message to multiple accounts, if you enable the tag
<img>
(to include an image) it gets sent in junk emails, but if only plain text is sent to inbox. Does anyone know why this is so? And how to solve it?
+1
show
source
to share
3 answers
- No, some email clients (especially webmail) will deprive something earlier
<body>
- You can use inline styles
<div style="">
- using an external .css file is not recommended as it cannot be loaded. - If you only have text and an image, it looks like spam. If you had more text, it could be interpreted in different ways.
0
source to share