acr
acr

Reputation: 1746

hyperlink in php html email not working

I am using below code to send email using php

<?php
$to = $_POST['emailbox'] ;
$message1 = nl2br($_REQUEST['output_textarea']);
$subject = 'script';
$message = "
<html>
<body>
<table bgcolor='Lavender' width='100%'>
<tr><td><font face=consolas>$message1</font></td></tr>
</table>

<br/><br/>

<a href="http://www.hyperlinkcode.com">Hyperlink Code</a>

</body>
</html>
";
$headers  = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\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);
?> 

But the hyper link mention in above code <a href="http://www.hyperlinkcode.com">Hyperlink Code</a> giving me below error:

Parse error: syntax error, unexpected T_STRING in eval()’d code on line 24

If I remove the the hyperlink line code from code, its working fine. how can I mention the hyperlink in email ?

Upvotes: 0

Views: 4015

Answers (2)

carrillo455
carrillo455

Reputation: 1

I think that the double quotes ("") are making some noise ¿?

Maybe you can try single quotes (''), like:

<a href='http://www.hyperlinkcode.com'>Hyperlink Code</a>

Sorry if i'm wrong..

Upvotes: 0

Sammitch
Sammitch

Reputation: 32272

Notice how the syntax highlighting breaks in your code? Notice that it happens when you use double quotes?

The simple answer is the change out:

<a href="http://www.hyperlinkcode.com">Hyperlink Code</a>

For:

<a href=\"http://www.hyperlinkcode.com\">Hyperlink Code</a>

But you can also do:

$message = <<<_E_
<html>
<body>
<table bgcolor='Lavender' width='100%'>
<tr><td><font face=consolas>$message1</font></td></tr>
</table>

<br/><br/>

<a href="http://www.hyperlinkcode.com">Hyperlink Code</a>

</body>
</html>
_E_;

It's called Heredoc syntax.

Upvotes: 1

Related Questions