flowingwindrider Posted July 8, 2007 Share Posted July 8, 2007 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. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 8, 2007 Share Posted July 8, 2007 code would be great, but yes you can as long as you escape quotes, and your email is a html email $body .= "<a href=\"mypage.html\">Click Here</a>"; //Note the \ before the " to escape them Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 8, 2007 Author Share Posted July 8, 2007 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? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 8, 2007 Share Posted July 8, 2007 show us the piece of your code pls Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 8, 2007 Author Share Posted July 8, 2007 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 ) ; Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 8, 2007 Share Posted July 8, 2007 first off you are closing your anchor wrong not [/url] its </a> secondly you never declared your email as an html message so it defautls to a text message and thus it shows it as text. Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 8, 2007 Author Share Posted July 8, 2007 Ok, I've fixed the anchor tag (and feel pretty dumb about that mistake). How do I declare the email as html? Thanks so much for the help. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 8, 2007 Share Posted July 8, 2007 // 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"; Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 8, 2007 Share Posted July 8, 2007 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... Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 8, 2007 Share Posted July 8, 2007 is there a reason you guys are using two different tags??? you use html (<a>) then you use bbcode ([/url]) ??? this doesnt make any sense Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 8, 2007 Share Posted July 8, 2007 he already realzied he mixed them the anchor is proper in this case Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 8, 2007 Share Posted July 8, 2007 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 ... ? Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 9, 2007 Author Share Posted July 9, 2007 // 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 Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 9, 2007 Share Posted July 9, 2007 $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"; Quote Link to comment Share on other sites More sharing options...
nloding Posted July 9, 2007 Share Posted July 9, 2007 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>"; Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 9, 2007 Author Share Posted July 9, 2007 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? Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 9, 2007 Author Share Posted July 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 9, 2007 Share Posted July 9, 2007 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()) Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 9, 2007 Author Share Posted July 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 9, 2007 Share Posted July 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 9, 2007 Author Share Posted July 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 9, 2007 Share Posted July 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
flowingwindrider Posted July 9, 2007 Author Share Posted July 9, 2007 Nope, still doesn't actually have a link although I've defined the $cancel variable just as you had it. I don't know what the problem is, but thanks for everything and have a great night's sleep! Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 9, 2007 Share Posted July 9, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.