Page 1 of 1

Sending Email using PHP but including HTML link

Posted: Fri May 20, 2011 10:21 am
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

Re: Sending Email using PHP but including HTML link

Posted: Fri May 20, 2011 11:22 am
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

Re: Sending Email using PHP but including HTML link

Posted: Fri May 20, 2011 12:38 pm
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);

Re: Sending Email using PHP but including HTML link

Posted: Fri May 20, 2011 12:48 pm
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);

Re: Sending Email using PHP but including HTML link

Posted: Sat May 21, 2011 5:20 am
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);
		
		
		
		?>

Re: Sending Email using PHP but including HTML link

Posted: Sun May 22, 2011 4:58 pm
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

Re: Sending Email using PHP but including HTML link

Posted: Tue May 24, 2011 1:41 pm
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.