/    Sign up×
Community /Pin to ProfileBookmark

Send an e-mail to a friend

Hi, I have a php script on my website which allows a user to e-mail their friends and tell them about the site. It works but I would like to improve it and I need a little bit of help in doing so.

I have friend.php which is basically the form:

[code=php]
</head>

<body background=”images/friendbg.gif”>
<form action=”process.php” method=”post” class=”style1″>
<div align=”left”><span class=”style2″> </span>
<table width=”300″ height=”360″ border=”0″>
<tr>
<td height=”49″><div align=”center”><span class=”style4″>Tell a friend about us!</span></div></td>
</tr>
<tr>
<td height=”220″><table width=”300″ border=”0″>
<tr>
<td width=”75″>Name:</td>
<td width=”215″><input type=”text” name=”name” size=”25″ maxlength=”50″ />
</tr>
<tr>
<td>E-Mail:</td>
<td><input type=”text” name=”email” size=”25″ maxlength=”50″ /></td>
</tr>
<tr>
<td>Subject:</td>
<td><input type=”text” name=”subject” size=”25″ maxlength=”100″ /></td>
</tr>
<tr>
<td align=”left” valign=”top”>Text:</td>
<td><textarea name=”text” cols=”19″ rows=”8″></textarea>
</td>
</tr>
</table>
<input type=”submit” name=”submit” value=”Send” /></td>
</tr>
<tr>
<td align=”center” valign=”bottom”><p class=”style6″>&nbsp;</p>
<p class=”style6″>&nbsp;</p>
<p class=”style6″>Copyright &copy; 2006.<br />
All Rights Reserved.</p></td>
</tr>
</table>
<br />
<br />
</div>
</form>
</body>
[/code]

I also have process.php:

[code=php]
<?php
ob_start();
?>
<!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=iso-8859-1″ />
<title>Untitled Document</title>
</head>

<body>

<?php
@extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = stripslashes($subject);
$text = stripslashes($text);

if (preg_match(“/^(w[w-.]*)@([w-.]+)$/”,trim($email),$matches)) {
$email = “{$matches[1]}@{$matches[2]}”;
} else {
die(“Sorry there was an error”);
}

$name = preg_replace(array(“/r/”,”/n/”),””,$name);
$subject = preg_replace(array(“/r/”,”/n/”),””,$subject);

mail($email,$subject,$text,”From:$name <‘[email protected]’>”);
header(“location:closefriend.html”);
?>

</body>
</html>
<?php
ob_end_flush();
?>
[/code]

When the user fills in the form, say using the following:

Name: Gary Roberts
E-mail: [email][email protected][/email]
Subject: Hello
Text: Hi

the e-mail arrives as follows:

[img]http://img.photobucket.com/albums/v662/gazroberts/ab0d7671.jpg[/img]

I would like it if the subject stated my e-mail address rather than Hello. I would also like to insert some text in to every e-mail, regardless of what the user types. In my own words I would like to describe my website, then have their message below it

Thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@web_dudeFeb 11.2006 — instead of using mail() I used [URL=http://phpmailer.sourceforge.net/]PHPMailer[/URL] .

I started using it, since some spam filters filtered my emails when using the mail() command, and using PHPMailer that simulates a regular email client solved the problem.
Copy linkTweet thisAlerts:
@G_a_r_yauthorFeb 12.2006 — Doing it that way doesn't really involve a lot of learning though!

Which is what I need!
Copy linkTweet thisAlerts:
@SheldonFeb 12.2006 — [code=php]
<?php
@extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$subject = $email ." - ".stripslashes($subject);
$text = stripslashes($text)."Thanks for signing up ".$name." have a great time";
$text .= "This will be sent at the bottom of the email";

if (preg_match("/^(w[w-.]*)@([w-.]+)$/",trim($email),$matches)) {
$email = "{$matches[1]}@{$matches[2]}";
} else {
die("Sorry there was an error");
}

$name = preg_replace(array("/r/","/n/"),"",$name);
$subject = preg_replace(array("/r/","/n/"),"",$subject);

mail($email,$subject,$text,"From:$name <'[email protected]'>");
header("location:closefriend.html");
?> [/code]
×

Success!

Help @G_a_r_y spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...