Reputation: 434
How to send html structure in email php ? The code below print a html structure as it is I want to send link
$email_message .= "<html><body><a href='http://www.rudraliving.com/brochure_images/$fname'>Download Attachment</a></body></a></html>"."\n\n";
Upvotes: 0
Views: 591
Reputation: 3299
Try this: more info
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer;
//smtp start-----------------------(if u use smtp then uncomment following block)
/* $mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'MANDRILL_USERNAME'; // SMTP username
$mail->Password = 'MANDRILL_APIKEY'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
*/
//smtp end-----------------------
$mail->From = '[email protected]';
$mail->FromName = 'Your From name';
//set to email
$mail->AddAddress('[email protected]','to_name'); // Name is optional
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
Upvotes: 0
Reputation: 2587
if you are on localhost you should have to use phpmailer library or swiftmailer, for sending html mail you have to set html headers "Content-type:text/html;charset=UTF-8"
for example
<?php
$to = "[email protected]";
$message .= "<html><body><a href='http://www.rudraliving.com/brochure_images/$fname'>Download Attachment</a></body></a></html>"."\n\n";>
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'Cc: [email protected]' . "\r\n";
mail($to,$subject,$message,$headers);
?>
Upvotes: 1