-1

I have a database "db" with a table "tb" which have image details that I upload to a folder and as well as the name and path of the image to database (table tb).

I have created a script for email in PHP as follows:

$recipients="example@gmail.com";

$subject="some subject";  

$headers= "'From: <example@mat.com>'";

$message="<a href='http://http://example.com/image/imagename.jpg' target='_blank'>Click here to see image</a>";

mail($recipients,$subject,$message,$headers);
}

Mail function working good but when the recipients received the mail, the link in body of the mail is shown as:

<a href='http://http://mcqpage.com/image/imagename.jpg' target='_blank'>Click here to see image</a>

I want that the recipients only recieve the "click here to see image" link and after click the target file open.

Jan Bluemink
  • 3,467
  • 1
  • 21
  • 35
hassanzeb
  • 15
  • 5

3 Answers3

1

When sending an email with PHP, you can set whether you want to send a plain text email or an HTML email. The default is plain text and none of the email content is parsed. That is why you see the link as a regular text instead of an HTML link.

To send an email with HTML content, you need to set the content-type header. So, your headers would be:

$headers= "'From: <example@mat.com>'" . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Note that you can also change the charset as appropriate.

trajchevska
  • 942
  • 7
  • 13
0

You need to set mail type in mail header as suggested by others:

$headers= "'From: <example@mat.com>'\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
d.coder
  • 1,988
  • 16
  • 23
0

You need to specify the message type in the headers:

$to = 'bob@example.com';
$from = 'nick.bull@example.com';

$subject = 'Website Change Request';

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
// This line is the most important!
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';

mail($to, $from, $message, $headers);
Nick Bull
  • 9,518
  • 6
  • 36
  • 58