PHP Mail() - How to Put an HTML Link in an Email

PHP mail() - How to put an html link in an email?

Try to add an header, so that the mail client doesn't believe it is plain text:

$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

See PHP mail function manual:

Example #4 Sending HTML email:

<?php
// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

How to insert a hyperlink in PHP email message?

Remove the escapes for your double quotes in

"<a href =\"www.example.com\">www.example.com</a>"
^ ^

and add http:// or https://

"<a href ="http://www.example.com">www.example.com</a>"

or

<a href ="http://www.example.com">www.example.com</a>

if you don't want quotes around it.


Tested with: (and assuming your SITE_NAME constant has already been defined, and other variables).

<?php

define("SITE_NAME", "Our Website!"); // I added that

$subject = "Thank you for registering to " . SITE_NAME;

$mail_content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<div>
<p>' . $user->first_name . ' ' . $user->lastname_name . ', thank you for registering to ' . SITE_NAME . '.</p>
<p>Please click the following link to proceed to the Questionnaire "<a href ="http://www.example.com">www.example.com</a>"</p>

</div>
</body>
</html>';

echo $mail_content;

Send HTML links in php mail message

I've checked with your code..

Seems like you are making a simple mistake..
You are not concatenating your code.. you are re assigning your header at line 3

Your Code

$emailid = $_POST['email'];
$phoneno = $_POST['phoneno'];
$to = "demoemail@gmail.com"; // this is your Email address
$from = $emailid; // this is the sender's Email address
$subject = "Intrested in scheduling appointment.";
$message = "<a href='http://www.google.com'>Click Here</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From:" . $from;
$retval = mail($to,$subject,$message,$headers);

Updated Code on headers:

    $headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:" . $from;

Update your header and try again!

Thanks! Have a nice day!

send a html link in a email sent by php

make sure you add headers correctly

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

SEE Example #4 Sending HTML email

send link using php mail() function

seems like your email function doesn't have good react with html tags, you probably missing this in you'r $header object.

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

read this,
https://css-tricks.com/sending-nice-html-email-with-php/

it has great explanation

html link in php mail

See Example #4, "Sending HTML Email", on the PHP mail() documentation page.

The issue is that your message needs MIME headers marking it as HTML rather than plain text.

PHP: sending link with mail don't work correctly

Try to use double quotes and escape those who belong to the mail text:

$message = "<a href=\"https://www.example.net/path/?Verify=". $IDVer ."\"> here</a>";


Related Topics



Leave a reply



Submit