Forum Moderators: coopster
using the following as the msg, I tried sending a message to my own addresss... the mail was sent sucessfully but as expected, it was recieved as it is. ie. along with the HTML tags. I understand that HTML cannot be used here
$msg = 'Hello ' . $mem_name . ',<br/> ' . $invitor . ' has invited you to join '.
'<a href="index.php">My community</a>
What is the other way to format the text and also include a link and add images to the mail?
Thanks
What is the other way to format the text and also include a link and add images to the mail?
To send html email, you need to
a) compose text/html mail headers,
b) you should make sure the output is a valid html document to reduce SpamAssassin points (e.g., "claims to be HTML type but no opening HTML element...")
Using your example (may need debugging,)
// If you set company name right here no reason to
// to an "if isset . . ."
$company_name='Your Company';
$url = 'http://www.example.com/';
$mail_subj = 'Join Our Community';
$from_email = 'no-reply@example.com'; //Small anti-spam precaution
$from_email = (isset($company_name))?'"'.$company_name.'" <'.$from_email.'>':$from_email;
$msg = '
<html>
<head>
<title>'
.$mail_subj.
'</title></head><body><p>Hello '
. $mem_name .
',</p><p> '
. $invitor .
' has invited you to join
'<a href="'.$url.'">My community</a></p></body></html>';
send_mail($to_email,$from_email,$mail_subj,$msg);
function send_mail($to,$from,$email_subj,$emailbody) {
// To send HTML mail, the Content-type header must be set
//Also a FROM field is required or it comes from anonymous.
$headers = "From: $from\r\n"; // Preformat as "company" <email>
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $email_subj, $emailbody, $headers);
}
You can send HTML emails using PHP's mail() [uk2.php.net] function (you should also include a text/plain section) but you need to specify that it's mime encoded and set the content-type to text/html. There is an example on the mail() manual page (link above).
You can send any kind of email using PHP's mail() function, attachments, embedded images etc. It's just that you need to do it yourself, which can be rather tedious, particularly because of the differences in email clients.
Does PHPmailer use PHP's mail() function in its implementation, or does it go that step further?
<a href="index.php">My community</a>
Also, any links will need to be an absolute URL (with protocol and fully qualified domain name).
Just to add... certain email clients will parse plain text emails and turn what it thinks are URLs into clickable links - but that is purely down to the email client.