Jump to content

php variable in HREF using mail


hey_suburbia

Recommended Posts

Hello All.

 

I'm having a bit of a hard time getting something (which I believe is rather simple) to work.

 

Here goes:

 

I have a Flash Holiday card sending a long query URL variable to PHP called "$message".

 

I tested just a simple send mail and everything works perfect:

 

<?php

$sendTo = $_POST["email"];
$subject = "Check out this Holiday Card I made";

$headers = "From: " . $_POST["name"] ." <" . $_POST["email"] .">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];

$message = $_POST["copycode"];

mail($sendTo, $subject, $message, $headers);

?>

 

Currently, the email body receives a VERY long URL.

 

I want to have the long URL hidden from view by just putting it into an HREF.

 

Something like this: 

<a href="{$message}">Your greeting card</a>

 

I'm pretty sure I'll have to send an html email, which is OK.  But I can't get the syntax to work. 

 

Can anyone offer advice/samples?

 

THANKS!

Link to comment
Share on other sites

Thank You,

 

I shall give it a try and report back!

 

Clients shouldn't parse HTML if it isn't defined to. Mailservers may flag your message as spam if you don't define the mail's MIME as HTML.

$header .= 'MIME-Version: 1.0' . "\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

 

This will allow the HTML to actually parse and the user to recieve the correct message you intended, Being nice to the client's mailserver.

Link to comment
Share on other sites

Here is what I came up with, but now I'm not receiving anything...??  I think it has something to do with the "$message2" variable that I setup to receive the flash variable "copycode"

 

<?php

$sendTo = $_POST["email"];
$subject = "Check out this Holiday Card I made";

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

$headers .= "From: " . $_POST["name"] ." <" . $_POST["email"] .">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";

$headers .= "Return-path: " . $_POST["email"];


$message2 = $_POST["copycode"];
$message = "<a href=\"{$message2}\">Your greeting card</a>"


mail($sendTo, $subject, $message2, $headers);

?>

Link to comment
Share on other sites

Here is what I came up with, but now I'm not receiving anything...??  I think it has something to do with the "$message2" variable that I setup to receive the flash variable "copycode"

 

Use a form to test the result from 'copycode' first. die as a secondary option if it doesn't send.

Link to comment
Share on other sites

This works:

<?php
$sendTo = $_POST["email"];
$subject = "Check out this Holiday Card I made";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: " . $_POST["name"] ." <" . $_POST["email"] .">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];
$message = $_POST["copycode"];
mail($sendTo, $subject, $message, $headers);
?>

 

This doesn't work:

<?php
$sendTo = $_POST["email"];
$subject = "Check out this Holiday Card I made";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: " . $_POST["name"] ." <" . $_POST["email"] .">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];
$flashVar = $_POST["copycode"];
$message = "<a href=\"{$flashVar}\">View Your Card/a>"
mail($sendTo, $subject, $message, $headers);
?>

 

For some reason this doesn't work either:

<?php
$sendTo = $_POST["email"];
$subject = "Check out this Holiday Card I made";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: " . $_POST["name"] ." <" . $_POST["email"] .">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];
$message = "<a href=\"{$message}\">View Your Card/a>"
mail($sendTo, $subject, $message, $headers);
?>

 

:'(

Link to comment
Share on other sites

GOT IT TO WORK!

<?php
$sendTo = $_POST["email"];
$subject = "Check out this Holiday Card I made";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: " . $_POST["name"] ." <" . $_POST["email"] .">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];
$flashVar = $_POST["copycode"];
$message = "<a href=\"{$flashVar}\">View Your Card /a>";
mail($sendTo, $subject, $message, $headers);
?>

 

The only problem now is that the email body shows "View Your Card /a>"

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.