Jump to content

[SOLVED] How do I put a link in a string?


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
Share on other sites

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: classifieds@bransonentertainersguild.com\n"

  . "Reply-To: classifieds@bransonentertainersguild.com\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 ) ;

Link to comment
Share on other sites

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 ... ?

Link to comment
Share on other sites

// 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: classifieds@bransonentertainersguild.com\n"
  . "Reply-To: classifieds@bransonentertainersguild.com\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

 

 

Link to comment
Share on other sites

$pfw_header = "From: classifieds@bransonentertainersguild.com\n"
  . "Reply-To: classifieds@bransonentertainersguild.com\n";

 

Should be ... concatenating $pfw_header:

 

$pfw_header .= "From: classifieds@bransonentertainersguild.com\n"
  . "Reply-To: classifieds@bransonentertainersguild.com\n";

Link to comment
Share on other sites

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: classifieds@bransonentertainersguild.com\n"
  . "Reply-To: classifieds@bransonentertainersguild.com\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>";

Link to comment
Share on other sites

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 = "classifieds@bransonentertainersguild.com";
$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?

Link to comment
Share on other sites

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: classifieds@bransonentertainersguild.com\n"
  . "Reply-To: classifieds@bransonentertainersguild.com\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.

Link to comment
Share on other sites

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())

Link to comment
Share on other sites

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: classifieds@bransonentertainersguild.com\n"
  . "Reply-To: classifieds@bransonentertainersguild.com\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.

Link to comment
Share on other sites

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

 

Remove the ; from the preceding line (which terminated the string you were trying to concatenate).

 

I think we're getting closer.

Link to comment
Share on other sites

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: classifieds@bransonentertainersguild.com\n"
  . "Reply-To: classifieds@bransonentertainersguild.com\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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

Your email program should allow you to see the html source of the message sent. That should give you ample clues as to what the end result actually is, and thus point you towards solving the last little problem.

Link to comment
Share on other sites

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.