Hi there,
I'm a complete novice to PHP so I bow down humbly to everyone on this forum.
My problem is this, I have got a very nifty PHP code to send e-cards from my website. The only problem is that I can't get the info in the "from" input in the form to read on the delivered email as "sender".
Example someone types into the form "from: Peter Griffin", the ecard is sent and in the recipients email box I want it to say under "Sender" "Peter Griffin".
It's hopefully a very simple solution for you guys but not for me.
I've added the code below and thank you in advance for reading this thread.
<?php
// CHANGE PARAMETERS HERE BEGIN
$columns = 5;
$senderEmail = 'E-card@blah.co.uk'; // Eg.: john@postcard.com
$senderName = 'senderName'; // Eg.: John's Postcards
// Change only if you have problems with urls
$postcardURL = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
// CHANGE PARAMETERS HERE END
// This function displays the available images
function displayPhotos(){
global $columns;
$act = 0;
// Open the actual directory
if ($handle = opendir("thumbs")) {
// Read all file from the actual directory
while ($file = readdir($handle)) {
if (!is_dir($file)) {
if ($act == 0) echo "<tr>";
echo "<td align='center'><img src='thumbs/$file' alt='postcard' /><br/><input type='radio' name='selimg' value='$file' /></td>";
$act++;
if ($act == $columns){
$act = 0;
echo "</tr>";
}
}
}
echo "</tr>";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Micro Postcard</title>
<link href="Temp/style/style.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><style type="text/css">
<!--
a:link {
color: #b0b7c7;
}
-->
</style></head>
<body>
<div id="main">
<div id="caption">Micro Postcard</div>
<?php if ( (!isset($_POST['submit'])) && (!isset($_GET['show'])) ) { ?>
<form action="<?php echo $_SERVER['Temp/PHP_SELF']; ?>" method="post">
<table align="center">
<?php displayPhotos(); ?>
</table>
<h2>Fill in the form</h2>
<table width="100%">
<tr><td>Send to (email address):</td><td><input type="text" name="email" size="30" /></td></tr>
<tr><td>Message:</td><td><textarea name="message" rows="10" cols="40"></textarea></td></tr>
<tr><td>From:</td><td><input type="text" name="senderName" size="30" /></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Send card!" name="submit"/></td></tr>
<background-color: #000;>
</table>
</form>
<?php } else if ( (isset($_POST['submit'])) && (!isset($_GET['show'])) ) {
$pic = isset ($_POST['selimg']) ? $_POST['selimg'] : '';
$filename = date('YmdGis');
$f = fopen('messages/'.$filename.".txt","w+");
fwrite($f,$pic."\n");
fwrite($f,$_POST['email']."\n");
fwrite($f,htmlspecialchars($_POST['message'])."\n");
fwrite($f,$_POST['senderName']."\n");
fclose($f);
// Compose the mail
$from = "From: $senderName <$senderEmail>\r\n";
$replay = "Reply-To: $senderEmail\r\n";
$params = "MIME-Version: 1.0\r\n";
$params .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$mailtext = "You have just received a virtual postcard!\r\n\r\n"
. "You can pick up your postcard at the following web address:\r\n"
. "$postcardURL"."?show=$filename\r\n\r\n"
. "We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n"
. "Regards,\r\n"
. "MicroPostcard\r\n"
. $postcardURL;
// Send email
@mail($_POST['email'],"You've received a postcard",$mailtext,$from.$replay.$params);
?>
<center>
Your postcard was sent successfully!<br/><br/>
<img src='images/<?php echo $pic; ?>' alt="postcard" /><br/><br/><br/><?php echo nl2br(htmlspecialchars($_POST['message'])); ?></center>
<?php } else if ( (!isset($_POST['submit'])) && (isset($_GET['show'])) ) {
$file = isset($_GET['show']) ? $_GET['show'] : '' ;
$content = file('messages/'.$file.".txt");
$pic = $content['0'];
unset ($content['0']);
unset ($content['1']);
$main = "";
foreach ($content as $value) {
$main .= $value;
}
?>
<center>
Your postcard!<br/><br/>
<img src='images/<?php echo $pic; ?>' alt="postcard" /><br/><br/><br/><?php echo nl2br(htmlspecialchars($main)); ?></center>
<?php } ?>
<div id="source"> Free E-card sent from <a href="http://www.stuart-howitt.co.uk" class="link">www.stuart-howitt.co.uk</a> using Micro Postcard 1.0</div>
</div>
</body>
e-card PHP help please.....
Moderator: General Moderators
- andym01480
- Forum Contributor
- Posts: 390
- Joined: Wed Apr 19, 2006 5:01 pm
Re: e-card PHP help please.....
Firstly edit your post and put BB code tags around your code - that will make it more readable and give line numbers!
At the start of the script
are set, so that's what they will be when the email is sent.
The form the user fills in only asks for Sender name, you need to add a senderEmail input line
Then you can replace the code above with...
BUT doing so makes your script a spammers paradise, especially as you have made your url public at the bottom of the script on this forum. The basic problem is that a spammer could add hundreds or thousands of email addresses to the form and send spam to everyone.
So you need to check that the entered email is one valid email address - Google php email validation and take your pick
And you need to check the name field has just letters and spaces - easier would be to separate first name and last name and just check for letters!
Then the form data is safer to use to send an ecard.
Come back when you have had a go!
At the start of the script
Code: Select all
$senderEmail = 'E-card@blah.co.uk'; // Eg.: john@postcard.com
$senderName = 'senderName'; // Eg.: John's PostcardsThe form the user fills in only asks for Sender name, you need to add a senderEmail input line
Then you can replace the code above with...
Code: Select all
$senderName=$_POST['senderName'];
$senderEmail=$_POST['senderEmail'];So you need to check that the entered email is one valid email address - Google php email validation and take your pick
And you need to check the name field has just letters and spaces - easier would be to separate first name and last name and just check for letters!
Then the form data is safer to use to send an ecard.
Come back when you have had a go!
Re: e-card PHP help please.....
Hi andym01480,
huge, huge thanks for your help, you're a star!!
Sorry about not putting BB tags around my code, will do for next time. No worries about the email address, I made it up so the evil spambots can't abuse it. Once again, big thanks.
Cheers
huge, huge thanks for your help, you're a star!!
Sorry about not putting BB tags around my code, will do for next time. No worries about the email address, I made it up so the evil spambots can't abuse it. Once again, big thanks.
Cheers