0

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";

2 Answers 2

1

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);
?>
Sign up to request clarification or add additional context in comments.

1 Comment

I am not on local host,I have uploaed on server
0

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';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.