Email Script Help

Hi all,

I’m trying to write a script that will allow a user to fill in a form to send the current page they are visiting to their friend. The script I have so far is written below:

<div class="send2friend">
<?php
if (isset($_POST['youremail']))
{
$title = $_POST['title'] ;
$url = $_POST['url'] ;
$email = $_POST['email'] ;
$youremail = $_POST['youremail'] ;
$sender = $_POST['yourname'] ;
$recipient = $_POST['friendname'] ;
$subject = 'I thought you might like this.';
$comment = $_POST['message'] ;
$message = $sender . "wanted to send you this link: " . $title . " (" . $url . ")
His/her comment: " . $comment ;
$from = "" . $sender . " <" . $youremail . ">";
$headers = "From: " . $from;
mail($recipient, $subject, stripslashes($message), $headers);
echo "Your mail has been sent. Click <a href='#'>HERE</a> to close the form.";
}
else
{
echo
'
<font class="formtitle">Send this page to a friend by e-mail.</font>
<br /><br />
Fill out the form below and click on submit to send this to your friend.
<br /><br />
<form method="post">
<input type="hidden" name="title" value="<?php the_title(); ?>">
<input type="hidden" name="url" value="<?php the_permalink(); ?> ">
Your Name: <input type="text" name="yourname" length="40"/> <br />
Your Email: <input type="text" name="youremail" length="50"/> <br /><br>
Friend\\'s Name: <input type"text" name="friendname" length="40" /><br>
Friend\\'s E-Mail: <input type="text" name="email" length="50" /><br /><br />
Include a message from you:<br />
<textarea rows="4" cols="50" name="message"> </textarea><br /><br />
<input type="submit" value="Send To Friend">
Cancel
</form>';
}
?>

</div>

the_title() and the_permalink() are both functions already defined on my blog so they will be picked up by the script as it will be placed on a blog page template, where these functions are already working.

I have 2 questions:

  1. Why is the email not being received? I have filled in the form on my test page and although it appears to have been sent (I get the thank you message), I do not actually receive any email.

  2. How can I put this into a DIV Overlay so the form appears when I click a specific link and then stays on the screen in the overlay to display the thank you message with a link to close the overlay? (I hope that makes sense).

Currently, the form is hidden on the page - I can see it by using the “inspect element” option in Google Chrome and highlighting the “send2friend” div class then unchecking the “display: hide” element of the CSS. This allows me to see and test the form but ideally, I want a link that will bring the form to focus and keep it there throughout the process and then hide it again when I click a different link.

The test page is here -> http://ivegotkids.com/aries-test-page
You can see the current form by right clicking on the lady’s picture in the top right and choosing “inspect element” in google chrome/firefox and then in the source, highlight the “send2friend” div just below it and uncheck the “display:none” CSS element.

I look forward to getting some help. Appreciation in advance.

I have no idea if this is a problem or not, but I would suggest you remove stripslashes() from the mail function and do that earlier. I doubt it belongs inside mail(), but I don’t know for sure.

E.g.

if ( get_magic_quotes_gpc() ) { 
	$message = stripslashes($message);
}

EDIT: PS, you can just check to see if your server has magic quotes on, and if not, you don’t need to bother with the stripslashes anyway. It should be off these days.

Ok - figured it out in the end it was the mail function didn’t have “email” in it so I’ve just changed it to:

mail($email, $subject, stripslashes($message), $headers);

And it works fine - I’ll hop on over to the CSS forums now to get help with the overlays.