Rob Crouch
Rob Crouch

Reputation: 53

sending HTML email with a variable in the URL

I am using the following script to send a dynamic page (php) as a html email... the page being emailed uses a variable in the URL to determine what record is shown from a database

<?

 $evid = $_GET['evid'];

    $to  = '[email protected]';
$subject = 'A test email!';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Put your HTML here
$message = file_get_contents('http://www.url.co.uk/diary/i.php?evid=2');

// Mail it
mail($to, $subject, $message, $headers);

?>

as you can see the html file being emailed has a evid variable... if i set this to $evid and try to send the variable when running the current script I get an error... does anyone know of a way round this?

hope i explained that clear enough Rob

Upvotes: 1

Views: 1434

Answers (3)

Nesim Razon
Nesim Razon

Reputation: 9794

$message = file_get_contents('http://www.url.co.uk/diary/i.php?evid='.$evid);

Upvotes: 0

user892607
user892607

Reputation:

Try concatenating the variable to the end of the url string like so:

$message = file_get_contents('http://www.url.co.uk/diary/i.php?evid=' . $evid);

Work for me

Upvotes: 0

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 175098

PHP won't evaluate variables in single-quotes strings.

$variable = "Hello World!";
echo '$variable'; //$variable
echo "$variable"; //Hello World!

Either move to double-quoted strings, or use the concantation operator (.):

echo 'string' . $variable; //stringHello World!

Upvotes: 2

Related Questions