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
https://forums.phpfreaks.com/topic/185484-php-variable-in-href-using-mail/
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.

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

?>

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.

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);
?>

 

:'(

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>"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.