Sending Email using PHP but including HTML link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

Sending Email using PHP but including HTML link

Post by davidhopkins »

Hello all.

Im struggling on something quite simple here !

I have a php script that is sending an email, it works fine apart from the fact that i cant get it to render the html link correct.

My email code is

Code: Select all

		$to      = "$email";
		$subject = "Register Complete";
		$message = "Hello $fname $sname, \n \nTo access your account please click on the following link: <a href='www.domain.com/login.php'>Login</a>";
		$headers = "From: noreply@domain.co.uk";
		mail($to, $subject, $message, $headers);
When the email comes thru it dosent put the link as a normal html link instead it puts <a href='www.domain.com/login.php'>Login</a> just like that

Any help would be great !

David
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Sending Email using PHP but including HTML link

Post by social_experiment »

Code: Select all

// add below your other '$header' variable
$headers .= 'MIME-Version 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
These headers will cause an html based email to be sent. Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

Re: Sending Email using PHP but including HTML link

Post by davidhopkins »

Thanks for that it works fine now apart from a little problem in the email address it says its being sent from

WHen i check the email the from is as follows noreply@domain.co.ukmime-version

I dont want the mimi-version to be shown

ALso when i click reply the address is

noreply@domain.co.ukmime-version, 1.0@s25284363.onlinehome-server.info

The php code im using is

Code: Select all

		$to      = "$email";
		$subject = "Login Details";
		$message = "Body text la la la";
		$headers = "From: noreply@domain.co.uk";
		$headers .= 'MIME-Version 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		mail($to, $subject, $message, $headers);
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Sending Email using PHP but including HTML link

Post by Jade »

Code: Select all

                $to      = "$email";
                $subject = "Login Details";
                $message = "Body text la la la";
                $headers = 'From: no-reply@domain.co.uk'. "\r\n";
                $headers .= 'MIME-Version 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                mail($to, $subject, $message, $headers);
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

Re: Sending Email using PHP but including HTML link

Post by davidhopkins »

Hey !

Thanks for the reply.

Using the code that Jade has supplied now sorts out the email address that the email is being sent from. It only displays noreply@domain.co.uk now which is what i want.

Although now the message isnt rendering the HTML code. It is just putting all as plain text again.

ANy idea why ?

THis is my code

Code: Select all

<?php


		$to      = "$email";
		$subject = "Login Details";
		$message = "Hello $fname $sname, <br><br>This is the message lalalal";
		$headers = 'From: no-reply@domain.co.uk'. "\r\n";
       	$headers .= 'MIME-Version 1.0' . "\r\n";
   		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		mail($to, $subject, $message, $headers);
		
		
		
		?>
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

Re: Sending Email using PHP but including HTML link

Post by davidhopkins »

Sorry to be a pain, But is any one able to help with this at all ?

At the moment its not rendering the HTML its just outputting it as normal text =[

Thanks
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Sending Email using PHP but including HTML link

Post by Jade »

Have you tried looking at the email in different email clients? If your email client is set to not display HTML then it will render it as regular text even if the header is set to use HTML.
Post Reply