Edited to try and make this read easier!
My company sends out HTML Emails, and I've ben instructed to create a "send to a friend" feature, because aparantly the "Forward" button isn't enough!
So, the user clicks the "send to a friend" link, which takes them to a web page. The url is actually a query string that captures the users name and email, to save them time, and also the URL of the web version of the HTML email:
send-to-a-friend.php/?sendersName=Drew&sendersEmail=name@gmail.com&webVersionURL=http://website.address/page.html
So I've got sendersName, sendersEmail and also webVersionURL to play with. Great.
I then have a form where this user can type in a name and email address of the intended recipient - recipientName and recipientEmail.
What I need to do is send the email when the form has been filled in. At the moment the code I have below sends it as soon as the page is loaded, which is not correct.
I do not know how to wrap the send email in a function that only sends once the form has been filled in, can anyone help with this part in particular?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>test send to a friend</title>
</head>
<body>
<p>Who do you want to send this email to?</p>
<form method="get" action="">
<input type="text" id="recipientName" value="" name="recipientName" />
<input type="text" id="recipientEmail" value="Email" name="recipientEmail" />
<?php
$_POST['recipientName'];
$_POST['recipientEmail'];
?>
<input type="submit" />
</form>
<hr />
<p>This is what your message will look like:</p>
<hr />
<p>Hi <strong>RECIPIENT</strong>, your friend <strong><?php echo $_GET["sendersName"]; ?></strong> (<?php echo $_GET["sendersEmail"]; ?>) thought you might be interested in this email from shelter!</p>
<p>------</p>
<p>
From: <?php echo $_GET["sendersName"]; ?> <br />
Sent: <?php date_default_timezone_set('Europe/London'); $date = date('d/m/Y h:i a', time()); echo $date; ?><br />
To: <strong>RECIPIENT</strong><br />
Subject: FWD: <strong>Subject Line</strong><br />
</p>
<iframe src="<?php echo $_GET["webVersionURL"]; ?>" width="700" height="400"></iframe>
<?php
$to = $recipientEmail;
// subject
$subject = "Test mail";
// message
$message = file_get_contents($_GET["webVersionURL"]);
// from
$from = "".$_GET["sendersName"]."<".$_GET["sendersEmail"].">";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
// Additional headers
$headers .= "From:" . $from;
// Mail it
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
</body>
</html>