How to get a Clickable Link inside this text string?

The code below is from a simple PHP script that sends a test email.
How can I get a clickable link inside this text based message string?
Note: My Page is going to be the clickable link.

$message = "Please Click on the link here: **My Page**";

You can do it via html using the usual anchor tag.

$message = "Please Click on the link here: <a href='my-page.html' title='My Page'>My Page</a>";
1 Like

Thank you Sam, I appreciate your reply!

However that is what I was doing but with double quotes not single and with double quotes the program will not run but with single quotes it runs but the code arrives in my email and not the actual link just the code. I was thinking I needed a PHP link maybe a variable inserted to produce the actual link. Any thoughts?

I’m good with HTML but a novice with PHP. Thank you!

you have to be careful how you mix your quotes in php as they will open or close the string.
If you open with double, then a subsequent double will close it (unless escaped), but a single won’t.
And vice-versa. Because you opened with doubles, I used singles on the attributes so as not to close.
You could open with singles, then use doubles in the attributes.
The other way is to escape the quotes with a backslash.

$message = "Please Click on the link here: <a href=\"my-page.html\" title=\"My Page\">My Page</a>";
1 Like

Hi Sam, thanks for the reply. :slight_smile:

When using this code:
<a href=\"https://apps.shopify.com/pixel-conversion-pro?reveal_new_review=true\">Pixel Conversion Pro Review</a>";

Now I get this error when running the script:
The pixelconversionpro.com page isn’t working
pixelconversionpro.com is currently unable to handle this request.
HTTP ERROR 500

Thanks again for your help!

This does not cause an error but all I get is the Code showing in my email and not the LINK.

<a href='https://apps.shopify.com/pixel-conversion-pro?reveal_new_review=true'>Pixel Conversion Pro Review</a>

Thanks again

Is it possible to show us the code you are using to output the link to email? It seems like you are having an escaping problem and without seeing the entire string its hard to judge what is happening by what you have provided.

1 Like

Yes…Thanks…give me a few hours to get back to my desk…Thanks again! :slight_smile:

Hi jgetner, ok I modified the script to be generic and shortened the Welcome Message…The script works and sends the email out from my domain perfectly but I’m unable to create a clickable App Review link inside the welcome message. Please advise…Thank you! :slight_smile:

<?php
$msg="";
if(isset($_POST['submit']))
{
$from_add = "support@domain.com"; 
$to_add = "customer@domain.com"; 
$subject = "Welcome TEST email";
$message = "
Test Email...Thanks
If you like our app please give us a positive review here: <a href='https://test.com'>App Review</a>
";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";

if(mail($to_add,$subject,$message,$headers)) 
{
$msg = "Mail sent OK";
} 
else 
{
$msg = "Error sending email!";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title>Test form to email</title>
</head>
<body>
<?php echo $msg ?>
<p>
This is a test of the php email system:
<form action='<?php echo htmlentities($_SERVER['PHP_SELF']); ?>' method='post'>
<input type='submit' name='submit' value='Submit'>
</form>
</p>
</body>
</html>

Give this a whirl setting the emailer content types so the email client doesn’t think its a plain text.

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

Thanks for the reply jgetner!

However I’m sorry to say it still shows the code and not the link when I receive the email in Outlook.

I appreciate your effort to help me. :slight_smile:

I think @jgetner is on the right track, in an email you do need to tell it to be html rather than plain text. I think there are some email clients that don’t accept html, but I would think Outlook does.
Not sure what to suggest. Maybe wait until the week and there are more in the forum.

1 Like

Thanks Sam, thanks for the reply…yes outlook accepts html links…I get them all the time. :slight_smile:

Thanks again!

Again, here is what the email link looks like when the PHP scripts sends me the email:
Again, if you like our app please give us a positive review here: <a href='https://apps.shopify.com/pixel-conversion-pro?reveal_new_review=true'>Pixel Conversion Pro Review</a>

But it should look like this:
Again, if you like our app please give us a positive review here: Pixel Conversion Pro Review

Hmm this is a very strange error indeed. I used your script on my own email and had no problems with the link showing up. Have you tried sending to different email clients? To make sure this is not a client error vs code error? My last advise would be to wrap the message in html tags as the links may not work on some clients without being inside of an html tags.

?php
$msg="";
if(isset($_POST['submit']))
{
$from_add = "support@domain.com"; 
$to_add = "customer@domain.com"; 
$subject = "Welcome TEST email";
$message = "<html>
Test Email...Thanks
If you like our app please give us a positive review here: <a href='https://test.com'>App Review</a>
</html>";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";

if(mail($to_add,$subject,$message,$headers)) 
{
$msg = "Mail sent OK";
} 
else 
{
$msg = "Error sending email!";
}
}
?>

If sending with the extra headers and wrapping in it in html tags my last advice would be to use wordwrap as some clients i guess use to have problems with lines exceeding 70 characters. IDK how true that is today but you never know.

1 Like

Thanks jgetner, I appreciate your reply! :slight_smile:

It’s not the client as it looks the same way on my iPhone it must be my hosting.

This is what it looks like with the html tags:

<html>
If you like our app please give us a positive review here: <a href='https://test.com'>App Review</a> </html>

This is what it looks like with out the tags:
If you like our app please give us a positive review here: <a href='https://test.com'>App Review</a>

Yeah since its showing the tag its working in plain/text mode. And by the code you have provided and if you updated with the suggested updates it should work no problem. You probably have a configuration setting set somewhere on something in your client or your email server or something but yeah there is nothing more i can think of as far as a code issue.

1 Like

Hi jgetner, thanks again for you kind reply!

I’m checking with my hosting now.

I also wonder if there is a way that the email comes from my domain directly and not on behalf of?

In other words I see the following send the email:
xyz123@server4445.web-hosting.com; on behalf of; me@mydomain.com

I would like the email to come from: me@mydomain.com

Anything I can do to the script to fix this?

I know this issue, I had the same problem, It was really long time ago, but I remember it was the PHP code, and too much overthinking.

anyways I use this header:

$email_header = "MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\nFrom: \"$title\"  <service@example.com>\r\nReply-To: \"$title\"  <service@example.com>\r\nX-Priority: 3\r\nX-Mailer: PHP 4\r\n";


I really can’t remember exactly, but I hope this helps.

You just need a simple HTML ($message) if you know HTML, I use tables to format my message, because it has worked better, also use inline styles.


$message='HTML';

(use ’ so you can easily use HTML, for variables inside message use message='text '.$var.' some text ';

1 Like

Just another idea to throw in, since i have no idea why this is not working.
Maybe try using PHPMailer to do this.
It’s something I’m going to look into as I currently use mail() but find it unreliable and quirky.
Though I never had trouble getting html in my emails, it’s usually things randomly not sending.

1 Like