Riviere February 2016

Add image and hyperlink in auto response email (after form submission)

I am new to php and building my first project.

I am creating a auto response email which will be sent to user after form submission.

The auto response email need to have content as follows,

Logo image

Thank you for contacting us.

Here you can view our case study.(need to link pdf file to view**)

I manage to get text. but not able to add image and hyperlink. tried using variable to store image url but code is visible instead of an image. i request if someone Please guide me.to solve this.

<?php
$to = $_POST['email'];
$from = "info@company.com"; 
$headers = "From: company";
$subject = "Thank you for contacting us.";
//$img='<img src="http://www.http://company.com/images/logo.jpg"/>';
$linkedin='Linkedin';
$twitter='Twitter';
$message=
"Dear ".$firstname." Thank you for contacting us.
Here you can view our case study.
www.company.com/data/casestudy.pdf
www.company.com | info@company.com | Linkedin | Twitter 
";
$mailsent = mail($to, $subject, $message, $headers);
?>

Answers


Pankaj Jha February 2016

First, In $header add content type to HTML

$headers .= "Content-type:text/html;charset=UTF-8";

http://php.net/manual/en/function.mail.php

This will set mail Content type to HTML, Now you can add all Tags and link of HTML without using variables, So full code will be like this

    <?php
        $to = $_POST['email'];
        $from = "info@company.com"; 
        $headers = "From: company";
        $headers .= "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        $subject = "Thank you for contacting us.";
        $message="<img src='http://company.com/images/logo.jpg'/>
       <br/>Dear ".$firstname." Thank you for contacting us.
       Here you can view our case study.
       <a href='www.example.com'>File Name </a>
       www.company.com | info@company.com |<a href='www.linkedin.com'>Linkedin</a> |<a href='twitter.com'> Twitter</a> 
            ";
            $mailsent = mail($to, $subject, $message, $headers); ?>

And don't get confused in single-quotes and double-quotes used here also i assume your $firstname has some value.

Post Status

Asked in February 2016
Viewed 3,268 times
Voted 14
Answered 1 times

Search




Leave an answer