Jump to content

Recommended Posts

I'm attempting to insert a link into the body of an email that I'm creating using the mail() function. Since everything in the $message variable is inside quotations, the link keeps printing the html code instead of creating a link. Can anyone help?

 

Sorry if this is a n00b question; I'm very new to PHP. Thanks in advance for any help you can provide.

Link to comment
https://forums.phpfreaks.com/topic/58982-solved-how-do-i-put-a-link-in-a-string/
Share on other sites

Sorry, but this just prints as text as well. I defined the variable

 

$cancel .= "<a href=\"brasonentertainersguild.com/cancel.htm\"click here[/url]";

 

and then put the $cancel variable into the $message variable of my email.

 

Where am I going wrong?

I've defined the $cancel variable as

 

$cancel .= "<a href=\"brasonentertainersguild.com/cancel.htm\"click here[/url]";

 

This goes into the body of the email as follows:

 

$pfw_header = "From: [email protected]\n"

  . "Reply-To: [email protected]\n";

$pfw_subject = "Your Ad Has Been Received";

$pfw_email_to = "$Email";

$pfw_message = "Thank you for your submission! We will post your ad online as soon as possible. Your ad will automatically expire one month from today.\n"

."\n"

. "Your Confirmation Number is: $conf_no. Please  $cancel if you'd like to cancel your ad before its expiration date.\n"

. "\n"

. "- Branson Entertainers Guild";

@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

also make sure you include a textual based link (not a anchor) because many email anti virus softwares will block anchors if they aren't from like google or ebay.  Use the customary

<a>click here</a> or copy and paste:

www.page.com

into your browser...

I'm attempting to insert a link into the body of an email that I'm creating using the mail() function. Since everything in the $message variable is inside quotations, the link keeps printing the html code instead of creating a link. Can anyone help?

 

Quick tip: if you post code in this forum between CODE tags, your links will not be changed to url :)

 

Possible solution to your problem. You have declared the mime type of the message to be text/html ... ?

// Always set content-type when sending HTML email

$headers = "MIME-Version: 1.0" . "\r\n";

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

 

Well, clearly I'm still quite uneducated when it comes to PHP. I still can quite figure this out. my code now looks like this:

 

$pfw_header = "MIME-Version: 1.0" . "\r\n";
$pfw_header .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$pfw_header = "From: [email protected]\n"
  . "Reply-To: [email protected]\n";
$pfw_subject = "Your Ad Has Been Received";
$pfw_email_to = "$Email";
$pfw_message = "Thank you for your submission! We will post your ad online as soon as possible. Your ad will automatically expire one month from today.\n"
."\n"
. "Your Confirmation Number is: $conf_no. Please  $cancel if you'd like to cancel your ad before its expiration date.\n"
. "\n"
. "- Branson Entertainers Guild";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

with the $cancel variable defined as

$cancel .= "<a href=\"brasonentertainersguild.com/cancel.htm\"click here</a>";

 

Please put your code in CODE tags

 

 

Like the guy above me said, use the CODE tags (the # sign above the reply box) to clarify your code.

 

$pfw_header = "MIME-Version: 1.0" . "\r\n";
$pfw_header .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$pfw_header = "From: [email protected]\n"
  . "Reply-To: [email protected]\n";
$pfw_subject = "Your Ad Has Been Received";
$pfw_email_to = "$Email";
$pfw_message = "Thank you for your submission! We will post your ad online as soon as possible. Your ad will automatically expire one month from today.\n"
."\n"
. "Your Confirmation Number is: $conf_no. Please  $cancel if you'd like to cancel your ad before its expiration date.\n"
. "\n"
. "- Branson Entertainers Guild";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 

with the $cancel variable defined as

 

$cancel .= "<a href=\"brasonentertainersguild.com/cancel.htm\">click here</a>";

 

Now I think you were missing a closing bracket on the <a> anchor ... what you had was:

 

"<a href=\"bransonentertainersguild.com/cancel.htm\"clickhere</a>";

So now my $cancel variable is defined as:

 

$cancel .= "<a href=\"brasonentertainersguild.com/cancel.htm\">click here</a>";

 

and the rest of the code is:

 

$pfw_header = "From: $Email\n"
  . "Reply-To: $Email\n";
  . "MIME-Version: 1.0" . "\r\n";
  . "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$pfw_subject = "New Classified Ad - Automobiles";
$pfw_email_to = "[email protected]";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "Price: $Price\n"
. "Manufacturer: $Manufacturer\n"
. "Model: $Model\n"
. "Year: $Year\n"
. "Mileage: $Mileage\n"
. "Color: $Color\n"
. "Accessories: $Accessories\n"
. "Description: $Description\n"
. "Email: $Email\n"
. "Telephone: $Telephone\n"
. "Picture1: $Picture1_URL\n"
. "Picture2: $Picture2_URL\n"
. "Picture3: $Picture3_URL\n"
. "Confirmation No: $conf_no\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 

Am I getting close?

Sorry, I pasted the wrong code fragment in the message above.

 

The $cancel variable is defined as:

 

$cancel .= "<a href=\"brasonentertainersguild.com/cancel.htm\">click here</a>";

 

but the rest of the code should read as follows:

 

$pfw_header = "From: [email protected]\n"
  . "Reply-To: [email protected]\n";
  . "MIME-Version: 1.0" . "\r\n";
  . "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$pfw_subject = "Your Ad Has Been Received";
$pfw_email_to = "$Email";
$pfw_message = "Thank you for your submission! We will post your ad online as soon as possible. Your ad will automatically expire one month from today.\n"
."\n"
. "Your Confirmation Number is: $conf_no. Please  $cancel if you'd like to cancel your ad before its expiration date.\n"
. "\n"
. "- Branson Entertainers Guild";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 

Sorry for the confusion.

First - get rid of the @ (error suppression) in the mail function.

 

Next: $pfw_email_to = "$Email"; should be $pfw_email_to = $Email; and I assume that $Email is defined somewhere as a real live email address ('free' email accounts are notoriously unreliable with mail())

Yes, $Email is defined earlier in the script. Actually, it is gathered from a form that this script is processing.

 

My code now looks like this:

 

$pfw_header = "From: [email protected]\n"
  . "Reply-To: [email protected]\n";
  . "MIME-Version: 1.0" . "\r\n";
  . "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$pfw_subject = "Your Ad Has Been Received";
$pfw_email_to = $Email;
$pfw_message = "Thank you for your submission! We will post your ad online as soon as possible. Your ad will automatically expire one month from today.\n"
."\n"
. "Your Confirmation Number is: $conf_no. Please  $cancel if you'd like to cancel your ad before its expiration date.\n"
. "\n"
. "- Branson Entertainers Guild";
mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 

I get an error message every time the server hits the . "MIME-Version: 1.0" . "\r\n"; line in my code.

You are so cool to keep sticking with me on this, and we are getting closer. I've removed the extra semicolons and now the script processes the form. However, the in the email it sends me the link doesn't work. Meaning, the text 'click here' is underlined and blue (so far so good) but it doesn't appear to lead anywhere. No information about the page the link should take you to appears at the bottom of my browser when I hover over the link, either.

 

My code now reads as:

 

$pfw_header = "From: [email protected]\n"
  . "Reply-To: [email protected]\n"
  . "MIME-Version: 1.0" . "\r\n"
  . "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$pfw_subject = "Your Ad Has Been Received";
$pfw_email_to = $Email;
$pfw_message = "Thank you for your submission! We will post your ad online as soon as possible. Your ad will automatically expire one month from today.\n"
."\n"
. "Your Confirmation Number is: $conf_no. Please  $cancel if you'd like to cancel your ad before its expiration date.\n"
. "\n"
. "- Branson Entertainers Guild";
mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 

Thanks again.

I assume the $cancel variable is still defined ... somewhere.

 

A reasonable form for it would be  as below. No concatenation needed in the definition:

 

$cancel = "<a href='bransonentertainersguild.com/cancel.htm'>click here</a>";

 

I hope that does it, because it's past my bedtime :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.