School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store | FORUMS

Class / Forums / php101 Refresh the current page Week #6 ADVANCED To-Do Assignment, post here
 

 (#11 2003-08-07 16:15:08) Post Reply

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Week #6 ADVANCED TO-DO ASSIGNMENT: Write a "Share these urls with your friends" script which will send a series of at least 3 different urls that the user must enter into the form to at least 3 different email addresses. Add in security to make sure that the "to" and "from" look like legitimate email addresses and use the $PHP_SELF variable. This should all be one self-contained script with NO include() or require() files.

Post this assignment here so that we can offer comment/critique for you, but also post a URL to the working copy of the script and the complete source code of the script in your post.

scriptname.php <-- script name

Good luck to you!

 

 (#79 2003-08-20 18:18:48) Post Reply

Sk8rRIMuk
Need To Set


Enrolled: Aug 2003
Posts: 39
AP: 1

Man appart from Week 3 Advanced which I can't do properly this has got to be the hardest one I have done.

My freinds have 15 e-mails in there inbox thx to this script h3h3.

Heres the URL to the working copy of the script:
http://www.katikai.com/ee/assi...rlemailform.php

As always you can find all my past projects at:
http://www.katikai.com/ee/assignment

In the usual style heer is my scripts code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Week #6 Advanced To-Do Assignment</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<table width="750" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top" width="750" height="500">
<?
//Check to see if the hidden value has been set yet if so execute the script
if($action=="send_mail"){
//Verify the e-mails are in the correct format
if(ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)",$receive0)){
if(
ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)",$receive1)){
if(
ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)",$receive2)){
if(
ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)",$email)){
//Set the array for the email address and count the variables
$recipients=array("$receive0","$receive1","$receive2");
$sizeof=count($recipients);
//Set how the subject and other details will look in the email
$subject="$topic";
$body_of_email="
Thise-mailwassentby$name,
Who'semailis:$email,
$namewouldliketosharethefollowingwebsiteswithyou:
$url0$url1$url2
$namealsoleftthiscomment:
$comment"
;
$additional_headers="From:$emailn";
//Set the for()
for($i=0;$i<$sizeof;$i++){
//Check to see if the form has been submitted correct and print the message if not print the error
if(mail($recipients[$i],$subject,$body_of_email,$additional_headers)){
print(
"<p align="center">Yourmailwassuccessfullysentto: <b>$recipients[$i]</b></p>");
}else{
print(
"<p align="center">Oops! something didn't work right above, check the syntax of your code.</p>");
}}
//If the email address is not valid display these error messgaes
}else{
print(
"<p align="center">Oops!Itappearsthatyouremail: <b>$email</b>isnotinthecorrectformat</p>");
}
}else{
print(
"<p align="center">Oops!Itappearsthatyouremail: <b>$receive2</b>isnotinthecorrectformat</p>");
}
}else{
print(
"<p align="center">Oops!Itappearsthatyouremail: <b>$receive1</b>isnotinthecorrectformat</p>");
}
}else{
print(
"<p align="center">Oops!Itappearsthatyouremail: <b>$receive0</b>isnotinthecorrectformat</p>");
}
//If the hidden input hasnt been set ignore all that code and print the form
}else{
?>
<h3>Fill out the form below to send your three chossen website URL's to your three chossen freins.</h3>
<form method="post" action="<?$PHP_SELF?>">
<input type="hidden" name="action" value="send_mail" />
Name: <input type="text" name="name" /><br />
Subject: <input type="text" name="topic" size="40" /><br />
Your Email: <input type="text" name="email" size="40" /><br />
Recipient One's Email: <input type="text" name="receive0" size="40" /><br />
Recipient Two's Email: <input type="text" name="receive1" size="40" /><br />
Recipient Three's Email: <input type="text" name="receive2" size="40" /><br />
URL One: <input type="text" name="url0" /><br />
URL Two: <input type="text" name="url1" /><br />
URL Three: <input type="text" name="url2" /><br />
Comments: <br /><textarea name="comment" cols="20" rows="10"></textarea><br />
<input type="submit" value="Submit" /><input type="reset" value="Reset" />
</form>
<?php
//Finally end the php code
}
?>
</td>
</tr>
</table>
</body>
</html>



I keep forgeting to comment my code :(

 

 (#180 2003-09-10 07:15:47) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

here's where i stopped the other time, once again can someone test it for me since my server doesnt have the mail() function enabled "for [******] security reasons"? thanks :)


<?
if($sent == "true") {
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $from) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to1) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to2) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to3)) {
$additional_headers = "From: $from\n";
$recipient = array("$to1\n, $to2\n, $to3\n");
$subject = "$name sent you his favourite urls!";
$body_of_email = "Message from $name:<br>$message<br><br>Urls sent:<br>$url1<br>$url2<br>url3<br>";
$addresses = count($recipient);
for(
$e=0; $e<$addresses; $e++) {
if (
mail($recipient[$e], $subject, $body_of_email, $additional_headers)) {
print(
"Email successfully sent!");
exit(); } else { print(
"<font color=\"ff0000\"><b>Error</b>: please make sure you fill in correctly all the fields in the form.</font>"); } } } else {
print(
"<font color=\"ff0000\"><b>Error</b>: please fill in correctly all three email addresses asked.</font>"); } }
?>

<form method="post" action="<? $PHP_SELF ?>">
<input type="hidden" name="sent" value="true">
Send your three favourite sites to your three best friends, just fill in all the fields.<br><br>
Your name: <input type="text" name="name" size="20"><br>
Your email: <input type="text" name="from" size="50"><br>
Friend: <input type="text" name="to1" size="50"><br>
Friend: <input type="text" name="to2" size="50"><br>
Friend: <input type="text" name="to3" size="50"><br>
Favourtie Url: <input type="text" name="url1" size"100"><br>
Favourtie Url: <input type="text" name="url2" size"100"><br>
Favourtie Url: <input type="text" name="url3" size"100"><br>
Aditional message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" value="send"><input type="reset" value="reset">
</form>


not entirely working url :P

 

 (#235 2003-09-18 01:39:32) Post Reply

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

Here is my Week#6 ADVANCED Assignment
http://members.lycos.co.uk/jef...an/class06a.php




<html>
<head><title>Start of the HTML </title></head>
<?

$actionmail
=$_REQUEST['actionform'];
$name=$_REQUEST['name'];
$frommail=$_REQUEST['frommail'];
$tomail1=$_REQUEST['tomail1'];
$tomail2=$_REQUEST['tomail2'];
$tomail3=$_REQUEST['tomail3'];
$url1=$_REQUEST['url1'];
$url2=$_REQUEST['url2'];
$url3=$_REQUEST['url3'];

$subheader=$_REQUEST['subheader'];
$mailbody=$_REQUEST['mailbody'];

if(
$actionmail == "sendmail")
{
$frommail="From:".$frommail;
$mailbody="This email is send from Class 06 Advanced Assignemnt Program
"
.$name." Bring to you following exciting links
"
.$url1."
"
.$url2."
"
.$url3."
Comments by him
"
.$mailbody;
if(
ereg('([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)', $tomail1) && ereg('([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)', $tomail2) && ereg('([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)', $tomail3))
{
if(
ereg('([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)', $frommail))
{
$tomail=$tomail1.",".$tomail2.",".$tomail3;
if(
mail($tomail,$subheader,$mailbody, $frommail))
{
echo(
"<br>mail successfully sent to $recipient.<br>");
echo(
$tomail."<br>");
} else
{
echo(
"<br>Oobs! something didn't work right above, error on $tomail <br>");
}
} else
{
echo(
"<br>Mail Address may be incorrect!!! Please Check it!!");
}
} else
{
echo(
"<br>Mail Address may be incorrect!!! Please Check it!!");
}
} else
{
}
print(
" <form method='POST' action= ".$_SERVER['PHP_SELF']." >");
print(
" <input type='hidden' name='actionform' value='sendmail' >");
print(
" <b>Name:</b><br> ");
print(
" <input type='text' name='name' size='50' value=''><br>");
print(
" <b>Your Email:</b><br>");
print(
" <input type='text' name='frommail' size='50' value=''><br>");
print(
" <b>Your Friend's Email 1:</b><br>");
print(
" <input type='text' name='tomail1' size='50' value=''><br>");
print(
" <b>Your Friend's Email 2:</b><br>");
print(
" <input type='text' name='tomail2' size='50' value=''><br>");
print(
" <b>Your Friend's Email 3:</b><br>");
print(
" <input type='text' name='tomail3' size='50' value=''><br>");
print(
" <b>Your Favorite URL 1:</b><br>");
print(
" <input type='text' name='url1' size='50' value=''><br>");
print(
" <b>Your Favorite URL 2:</b><br>");
print(
" <input type='text' name='url2' size='50' value=''><br>");
print(
" <b>Your Favorite URL 3:</b><br>");
print(
" <input type='text' name='url3' size='50' value=''><br>");
print(
" <b>Subject:</b><br>");
print(
" <input type='text' name='subheader' size='50' value='Hello, my friends, I brought U new URLs'><br>");
print(
" <br><b>Comments:</b><br>");
print(
" <textarea name='mailbody' cols='39' rows='10'></textarea><br>");
print(
" <input type='submit' value='Submit'>");
print(
"</form>");

?>
</html>





 

 (#262 2003-09-22 05:24:51) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

finnaly, i tested it, it had a bug


<?
global $PHP_self;
if(
$sent == "true") {
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $from) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to1) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to2) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to3)) {
$additional_headers = "From: $from\n";
$recipient = array("$to1\n", "$to2\n", "$to3\n");
$subject = "$name sent you his favourite urls!";
$body_of_email = "Message from $name:
$message

Urls sent:
$url1
$url2
$url3
"
;
$addresses = count($recipient);

for(
$e = 0; $e < $addresses; $e++) {
if (
mail($recipient[$e], $subject, $body_of_email, $additional_headers)) {
print(
"Email successfully sent to $recipient[$e]!<br>");
} else { print(
"<font color=\"ff0000\"><b>Error</b> sending email to $recipient[$e].</font>"); } } } else {
print(
"<font color=\"ff0000\"><b>Error</b>: please fill in correctly all three email addresses asked.</font>"); }
exit(); }

?>

<form method="post" action="<? $PHP_SELF ?>">
<input type="hidden" name="sent" value="true">
Send your three favourite sites to your three best friends, just fill in all the fields.<br><br>
Your name: <input type="text" name="name" size="20"><br>
Your email: <input type="text" name="from" size="50"><br>
Friend: <input type="text" name="to1" size="50"><br>
Friend: <input type="text" name="to2" size="50"><br>
Friend: <input type="text" name="to3" size="50"><br>
Favourtie Url: <input type="text" name="url1" size"100"><br>
Favourtie Url: <input type="text" name="url2" size"100"><br>
Favourtie Url: <input type="text" name="url3" size"100"><br>
Aditional message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" value="send"><input type="reset" value="reset">
</form>


not entirely working url - like i said, the uploaded file doesnt send emails because of the server, but i guarantee you it works :)

 

 (#290 2003-09-27 03:13:48) Post Reply

maddy
Need To Set


Enrolled: Sep 2003
Posts: 14
AP: 1

Seems to work. Not quite sure.Relied heavily on the code already posted here, especially in validating the multiple email addresses. Can we get a "model" type answer for this?
<?
if($sent == "true") {
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $fromemail) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $toemail1) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $toemail2) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $toemail3)) {
$additional_headers = "From: $fromemail";
$recipient = array($toemail1, $toemail2, $toemail3);
$subject = "$fromname wants you to visit these sites!";
$body_of_email = "Check out these sites:

$url1
$url2
$url3
"
;
$friends = count($recipient);

for(
$f = 0; $e < $friends; $f++) {
if (
mail($recipient[$f], $subject, $body_of_email, $additional_headers)) {
print(
"Email successfully sent to $recipient[$f]!<br>");
} else { print(
"There was an error sending email to $recipient[$f]."); } } } else {
print(
"Please check that ALL email addresses are in the correct format."); }
exit(); }

?>
<h3>Share 3 sites with 3 friends!</h3>
<form method="post" action="<? $PHP_SELF ?>">
<input type="hidden" name="sent" value="true">
Your name: <input type="text" name="fromname"><br>
Your email: <input type="text" name="fromemail"><br> <br />
Friend's Email: <input type="text" name="toemail1"><br>
Friend's Email: <input type="text" name="toemail2"><br>
Friend's Email: <input type="text" name="toemail3"><br> <br />
<h4>URLs to recommend:</h4>
Site: <input type="text" name="url1"><br>
Site: <input type="text" name="url2"><br>
Site: <input type="text" name="url3"><br>
<input type="submit" value="Send">
</form>


 

 (#314 2003-10-12 11:01:22) Post Reply

jlk242
Need To Set


Enrolled: Oct 2003
Posts: 8
AP: 1

Oopsy! I posted my code orginally to the basic section, I hope i don't get detention....

I think it might work in theory, but my server tells me I am not allowed to do this...it doesn't show a Parse, just a forbidden message.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>_-=+:: The House of Lycaon ::+=-_</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="141D51" text="#FFFFFF" link="#FFFFFF">
<?php
$set
= 0;
$subject = "Hey Check out these links!";
if (
$action == "send_mail"){
echo (
" $action ");
$set = 1;
$recipient = array($recipient1,$recipient2,$recipient3);
$body_of_email = array('$link1\n','$link2\n','$link3\n');
$additional_headers = "From: $sender\n";
$size = count($recipient);
}
$i = 0;
while (
$i < $size)
{
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $recipient[$i]))
{
if(
mail("$recipient[$i]","$subject","$body_of_email","$additional_headers"))
{

echo(
"<p> Links successfully sent to $recipient[$i]</p>");

}
else
{
$set = 0;
echo(
"<p>I am sorry, but the links were not sent to $recipient[$i]</p>");
}
}
else
{
$set = 0;
echo(
"<p>I am sorry, but: $recipient[$i] is not in the correct format</p>");
}
$i++;
}
?>
<table width="78%" border="0" align="center">
<form name="mail_form" method="post" action=" <? $PHP_self ?> ">
<input name="action" type="hidden" value="send_mail">

<tr>
<td>
<div align="center"><img src="images/form_head.gif" width="400" height="160"></div></td>
</tr>
<tr>
<td>
<div align="left">
<p align="center">
</p>
<p align="center">To:
<input name="recipient1" type="text" id="recipient1" size="50" maxlength="100">
</p>
<p align="center">To:
<input name="recipient1" type="text" id="\recipient2" size="50" maxlength="100">
</p>
<p align="center">To:
<input name="recipient1" type="text" id="\recipient3" size="50" maxlength="100">
</p>
</div>
</td>
</tr>
<tr>
<td height="21">
<div align="center">From :
<input name="sender" type="text" id="sender" size="50" maxlength="100">
</div>
</td>
</tr>
<tr>
<td height="49">
<div align="center">
<p>Link #1
<input name="link1" type="text" size="50" maxlength="100">
<br>
Link #2
<input name="link2" type="text" size="50" maxlength="100">
<br>
Link #3
<input name="link3" type="text" size="50" maxlength="100">
</p>
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
<input type="submit" name="Submit" value="Submit">
</div>
</td>
</tr>
</form>
</table>
</body>
</html>


 

 (#392 2003-11-19 16:13:03) Post Reply

zxrod
Need To Set


Enrolled: Oct 2003
Posts: 7
AP: 1

I forgot to post a comment with my week 6 basic assignment. Oh well. This appears to work fine so yay!

<html>
<body>


<title>Week 6 Advanced: Share these URLs with your friends</title>
<?
$emails
=array($friend1, $friend2, $friend3);
$numails= count($emails);
$urls=array($url1, $url2, $url3);
$subject="$name has some links for you";
$message="$name wanted to tell you about: $url[0], $url[1], and $url[2]. Thank you";
$additional_headers="From $name";
if(
$action=="send_emails") {
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $email)) {
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $friend1)) {
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $friend2)) {
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $friend3)) {
for(
$i; $numails; $i++) {
if(
mail($emails[$i],$subject, $message, $additional_headers)) {
print(
"Your emails have been sent");
} else {
print(
"There was an error in your syntax above, please check and try again");
}
} } else {
print(
"There was an error in the syntax for the email address of $friend3");
} } else {
print(
"There was an error in the syntax for the email address of $friend2");
}
} else {
print(
"There was an error in the syntax for the email address of $friend1");
} } else {
print(
"There was an error in the syntax for the email address of $email");
} } else {
?>
<form method="Post" action="<? $PHP_SELF ?>">
<input type="hidden" name="action" value="send_emails">
Your name:<input type="text" name="name"><br>
Your email:<input type="text" name="email">
<p>First friends email:<input type="text" name="friend1"><br>
Second friends email:<input type="text" name="friend2"><br>
Third friends email:<input type="text" name="friend3"><br>
<p>First URL:<input type="text" name="url1"><br>
Second URL:<input type="text" name="url2"><br>
Third URL:<input type="text" name="url3"><br>
<input type="submit" value="Submit">
</form>
<? } ?>



</body>
</html>

 

 (#621 2004-06-06 15:34:50) Post Reply

Ahkorahil
Need To Set


Enrolled: Oct 2003
Posts: 20
AP: 1

<!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>
<title>6th (advanced) assignment in pHp</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
if($action == "send_mail") {
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $f1)) {
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $f2)) {
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $f3)) {
$get = array($f1, $f2, $f3);
$size = count($get);
$subject = "Url's";
$header = "oneman@hot.ee";
$body_of = "I send to You some links to watch:\n <a href =\"$u1\">url 1</a>\n <a href =\"$u2\">url 2</a> \n <a href =\"$u3\">url 3</a>";
for($a = 0; $a < $size; $a++) {
if(mail($saaja[$a], $subject, $body_of, $header)) {
print("Mail sent");
} else {
print("recipient has been written wrong"); }
} /// suleb FOR
} else {
print("freind3 is wrong"); }
} else {
print("freind2 is wrong"); }
} else {
print("freind 1 is wrong"); }
}else {
?>
<form method = "post" action = "<?php $PHP_SELF ?>">
<input type = "hidden" name= "action" value = "send_mail" />
To freind #1: <input type = "text" name="f1" value ="" size ="20" /><br />
To freind #2: <input type = "text" name = "f2" value = "" size = "20" /><br />
To freind #3: <input type = "text" name = "f3" value = "" size = "20" /><br />
URL #1: <input type = "text" name = "u1" value = "" size = "20" /><br />
URL #2: <input type = "text" name = "u2" value = "" size = "20" /><br />
URL #3: <input type = "text" name = "u3" value = "" size = "20" /><br />
<input type = "submit" value = "SEND" />
</form>
<?php } ?>
</body>
</html>

<a href="http://members.lycos.co.uk/rain086/php/6a.php"> working code </a>



// This advanced assignment was little bit easier, because I had lots of trouble with basic assignment :)

 

 (#622 2004-06-06 15:37:06) Post Reply

Ahkorahil
Need To Set


Enrolled: Oct 2003
Posts: 20
AP: 1

Hello again,
I have very noobic question and I shame to say it, but how do I add working link to my assingment code when I post it in the forum ?
thanks for help

 

 (#672 2004-07-18 20:58:12) Post Reply

def
Need To Set


Enrolled: Jul 2004
Posts: 10
AP: 1



<?
if ($email_submit == "true") { // execute upon form completion

$recipients_array = array("$email_recepient_1","$email_recepient_2","$email_recepient_3");
$recipient_array_size = count($recipients_array);
$urls_array = array("$email_url_1","$email_url_2","$email_url_3");
$subject = "php multiple recipient email script";
$additional_headers = "From: $email_user\n";
$body_of_email = "first url: $email_url_1\n second url: $email_url_2\n third url: $email_url_3\n";

if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $email_user)) { // check validity of user email
for ($i = 0 ; $i < $recipient_array_size; $i++) { // if user email is valid, begin loop to check validity of recipients emails
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $recipients_array[$i])) { // check validity of recipients emails
} else {
print(
"\"$recipients_array[$i]\" is not a valid recipient email address"); exit(); // report if recipient email address is invalid
}
}

for (
$i = 0 ; $i < $recipient_array_size; $i++) { // if all emails are valid begin loop to send mails
if(mail($recipients_array[$i], $subject, $body_of_email, $additional_headers)) { // check mail functionality
print("mail successfully sent to $recipients_array[$i]<br>"); // mail success
} else {
print(
'server mail function disabled<br>'); exit(); // mail failure
}
}
} else {
print(
"$email_user is not a valid user email address<br>"); // report if user email address is invalid
}
}
?>

<form method="post" action="<? $PHP_SELF ?>">
<p>your email adress:<br>
<input name="email_user" type="text" size="30">
<br>
recipient's email adresses:<br>
<input name="email_recepient_1" type="text" size="30">
<input name="email_recepient_2" type="text" size="30">
<input name="email_recepient_3" type="text" size="30">
<br>
urls:<br>
<input name="email_url_1" type="text" size="30">
<input name="email_url_2" type="text" size="30">
<input name="email_url_3" type="text" size="30">
<br>
<input name="email_submit" type="hidden" value="true">
<br>
<input type="submit" name="Submit" value="Submit">
</p>
</form>


 

 (#713 2004-10-12 11:49:51) Post Reply

lestat
Need To Set


Enrolled: Jan 2004
Posts: 44
AP: 1

I am way stuck on getting my loop to work. This code only shows sending the mail - without validating the email. Just trying to get this to work before adding more code to it.
Any help would be appreciated!


<?

// Assigning variables to typed data
$email1 = $_REQUEST['email1'];
$email2 = $_REQUEST['email2'];
$email3 = $_REQUEST['email3'];

$url1 = $_REQUEST['url1'];
$url2 = $_REQUEST['url2'];
$url3 = $_REQUEST['url3'];

$from = $_REQUEST['from'];

// Headers of email
$subject = 'Some URLS that $from thought you may like';
$body_of_email = 'weeeeeeeeeee';
$additional_headers = 'From: $from\n';

// Set Array of recipients from input data
$recipient = array('$email1' , '$email2' , '$email3');
$urls = array('$url1' , '$url2' , '$url3');

// Count Email & Arrays
$size_of_emails = count($recipient);
$size_of_urls = count($urls);

// Action for when button is pushed
if($_POST['button'] == "push"){

for(
$i = 0; $i < $size_of_emails; $i++) {
if(
mail($recipient[$i], $subject, $body_of_email, $additional_headers)) {
print(
"<br>mail sent to $recipient");

}else{
print(
"nope ");
}
}
}
?>



 

 (#714 2004-10-12 14:39:12) Post Reply

lestat
Need To Set


Enrolled: Jan 2004
Posts: 44
AP: 1

OK finished this. I'm sure it could be cleaned up a little. Please critique. Thanks!
Working url:http://www.timslan.com/scriptskewl/week6/wk6adv.php


<html>
<head>
<title>Week #6 Advanced ~ Lestat</title>
<link rel="stylesheet" type="text/css" href="/html/css/scriptskewl.css">
</head>

<body>
<?

// Assigning variables to typed data
$email1 = $_REQUEST['email1'];
$email2 = $_REQUEST['email2'];
$email3 = $_REQUEST['email3'];

$url1 = $_REQUEST['url1'];
$url2 = $_REQUEST['url2'];
$url3 = $_REQUEST['url3'];

$from = $_REQUEST['from'];

// Headers of email
$subject = "Thought you may like these...";
$body_of_email = "$from thought you would like these:
$url1
$url2
$url3"
;

$additional_headers = "From: $from\n";

// Set Array of recipients from input data
$recipient = array("$email1" , "$email2" , "$email3");
$urls = array("$url1" , "$url2" , "$url3");

// Count Email & Arrays
$size_of_emails = count($recipient);
$size_of_urls = count($urls);

// Action for when button is pushed
if($_POST['button'] == "push"){

// If the sender address is good - validate recipients email
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $from)) {

// Loop through recipient email
for($i = 0; $i < $size_of_emails; $i++) {

// Validate recipient email
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $recipient[$i])) {

// Process email
if(mail($recipient[$i], $subject, $body_of_email, $additional_headers)) {

// If mail process is good - send mail
print("<br>mail sent to $recipient[$i]");

// If mail process is bad - bail out
}else{
print(
"<br>There was a problem with the form. Mail was not sent.");
}

// If recipient address is bad - print denial message
}else{
print(
"<br>Mail not sent to $recipient[$i], invalid email format.");
}
}

// If sender address is bad - bail out
}else{
print(
"$from is not a valid sender address. Mail not sent");
}
}


?>

<form method='POST' action='<? PHP_SELF ?>'>
<input type='hidden' name='button' value='push'>
<table border='0'>
<tr>
<td colspan='2'><u><h4>Share these URLS with your friends</h4></u></td>
</tr>
<tr>
<td>
<strong>To:</strong><br>
Email 1&nbsp;<input type='text' name='email1' size='30'><br>
Email 2&nbsp;<input type='text' name='email2'size='30'><br>
Email 3&nbsp;<input type='text' name='email3'size='30'><br>
<br>
<strong>URL's to Share:</strong><br>
URL 1&nbsp;<input type='text' name='url1' size='30'><br>
URL 2&nbsp;<input type='text' name='url2' size='30'><br>
URL 3&nbsp;<input type='text' name='url3' size='30'><br>
<br>
From:&nbsp;<input type='text' name='from' size='30'><br><br>
<center><input type='submit' value='submit'>&nbsp;<input type='reset' value='reset'></center>
</td>
</tr>
</table>
</form>
</body>
</html>


 

 (#782 2005-03-06 11:00:02) Post Reply

zman
Need To Set


Enrolled: Feb 2005
Posts: 15
AP: 1

My Advanced Assignment #6:



<html>
<head>
<title>ScriptSchool.com Assignment 6 (advanced)</title>

</head>
<body bgcolor="666666">

<?php
// ScriptSchool.com Assignment 6 (advanced)
/* Description of assignment: Write a "Share these urls with your friends"
// script which will send a series of at least 3 different urls that the user
// must enter into the form to at least 3 different email addresses. Add in
// security to make sure that the "to" and "from" look like legitimate email
// addresses and use the $PHP_SELF variable. This should all be one
// self-contained script with NO include() or require() files.*/
print("<center><p><b>ScriptSchool.com Assignment 6 (advanced)</b><br />
Description of assignment: Write a \"Share these urls with your friends\"<br />
script which will send a series of at least 3 different urls that the user<br />
must enter into the form to at least 3 different email addresses. Add in<br />
security to make sure that the \"to\" and \"from\" look like legitimate email<br />
addresses and use the \$PHP_SELF variable. This should all be one<br />
self-contained script with NO include() or require() files.</p></center>"
);

// check to see if the send_mail action is being sent. If not, then that means
// we haven't displayed the form yet, so let's do so.
if($action == "send_mail")
{
// assign variables, and create an array of recipients called $to. $body
// formats the contents of the form in a readable manner in the end message.
$to = array($recipient1,$recipient2,$recipient3);
$from = $email;
$additional_headers = "From: $email\n";
$subject = "Some recommended websites from $name";
$body = "
This is the contents of the email from $name,
whose email address is $email.
$name has recommended the following websites...

$url1:
$url1comments

$url2:
$url2comments

$url3:
$url3comments

$addlcomments "
;

// check that the $from email address is valid. If not, display an error
// message to tel the user to go back and try again, and bail out.
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\-]+\.+)", $from))
{
// start a while loop to process the recipient addresses one by one
$a=0; // assign the starting index value
while($a<3)
{
// first, let's see if there is anything in the address field at all.
// If not, just skip it and try the next one (just in case).
if($to != '')
{
// we now know there is something there, so let's see if it is a
// valid email address before we proceed further. If it is not valid
// then skip it over, and display a message to that effect.
$recipient = $to[$a];
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\-]+\.+)", $recipient))
{
// ok, it appears to be a valid email address, let's send to it.
// If that fails, through a nice vague message about the server. <grin>
if(mail($recipient,$subject,$body,$additional_headers))
{
print(
"<center>mail successfully sent to $recipient</center>");
}
else
{
print(
"<center>Oops! Failed to send message to $recipient. This may be caused by a server problem.</center>");
}
}
else
{
print(
"<center>Sorry, but the recipient email address, $recipient, did not appear to be legitimate. - <b>Address skipped</b></center>");
}
}
$a++;
}
}
else
{
print(
"<center>Soory, but your provided email address, $from, does not appear to be legitimate.<br /><b>Please page back, make any corrections, and try again.</b></center>");
}
}
else
{
?>
<center><form METHOD=POST action="<? $PHP_SELF ?>">
<input type="hidden" name="action" value="send_mail">
Share your favorite URLs with some friends<br />
Please enter your name, your email address, and the email addresses of up<br />
to three friends, and up to three of your most recommended websites and<br />
a couple words telling why you are recommending each.<br />
Finally, you can add a general comment, if you like.<br /><br />
<b>Note that the fields have been pre-filled for test purposes.<br />
To test for correct function, mangle up an email addy and see what happens.<b><br /><br />
Your Name: <input type="text" name="name" size=20 value="Eric">
Your Email: <input type="text" name="email" size=20 value="eric@pruss.net"><br />
First recipient email: <input type="text" name="recipient1" size=40 value="test1@garagechoppers.com"><br />
Second recipient email: <input type="text" name="recipient2" size=40 value="test2@garagechoppers.com"><br />
Third recipient email: <input type="text" name="recipient3" size=40 value="test3@garagechoppers.com"><br />
Please recommend three websites.
First Website: <input type="text" name="url1" size=40 value="http://garagechoppers.com"><br />
Why are you recommending this site?:<br /><textarea rows="2" cols="40" name="url1comments">All you need to know to build the coolest choppers!</textarea><br /><br />
Second Website: <input type="text" name="url2" size=40 value="http://bloggingpoet.com"><br />
Why are you recommending this site?:<br /><textarea rows="2" cols="40" name="url2comments">More than just poetry!</textarea><br /><br />
Third Website: <input type="text" name="url3" size=40 value="http://rumblebee.org"><br />
Why are you recommending this site?:<br /><textarea rows="2" cols="40" name="url3comments">All about the Rumble Bee!</textarea><br /><br />
Any additional comments:<br /><textarea rows="2" cols="40" name="addlcomments">I think these sites are cool, and hope that you will enjoy them!</textarea><br />
<input type="submit" value="Submit"></form>
<? }
?>


</body>
</html>


 

 (#830 2005-06-07 05:29:32) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

My week 6 assignment

<?
$recipients=array($_POST["email_1"],$_POST["email_2"],$_POST["email_3"]);
$url=array($_POST["body_of_email_1"],$_POST["body_of_email_2"],$_POST["body_of_email_3"]);
$c1=count($mail);
$recipient=$_POST["recipient"];
$subject=$_POST["subject"];
$body=$_POST["body_of_email"];
$headers='FROM:$_POST["from"]\n';
$size=count($recipients);
if($_POST["action"]=="mail"){
for($i=0;$i<$size;$i++){
$mas=$recipients[$i]; $bod=$url[$i];
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)",$mas))
{
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)",$_POST["from"])) {
if(mail($mas,$subject,$bod,$headers))
{print("mail(s) successfully sent to e-mail adress specified"); }
else { print("error,your mail has not been sent");}
} //close from
else{echo"your from is invalid";}
} //close mail
else{print("oops it appears like your mail(s):is not in the correct format");}
}
}

?>
<br><br><br><br><br>
<form method="POST" action="<?PHP_SELF?>">
<input type="hidden" value="mail"name="action">
url1<input type="text"name="body_of_email_1"><br>
e-mail1<input type="text"name="email_1"> <br>
url2<input type="text"name="body_of_email_2"> <br>
e-mail2<input type="text"name="email_2"><br>
url3<input <input type="text"name="body_of_email_3"><br>
e-mail3<input type="text"name="email_3"> <br>
from<input type="text"name="from"><br>
<input type="submit">



working url:
[url] http://www.programare-me.as.ro\basic.php
[/url]

 

 (#970 2006-03-20 07:16:14) Post Reply

Russell
Need To Set


Enrolled: Mar 2006
Posts: 19
AP: 1

not pretty but it works. i should spend a bit more time on it but its late and im tired. thanks Sk8rRIMuk and Quicksaver.


<center>

<?
if($action=="true"){
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $senders_email)){
$recipients=array($friend1_email,$friend2_email,$friend3_email);
$urls=array('$url1','$url2','$url3');
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $recipients[0]) &&
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $recipients[1]) &&
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $recipients[2])){
$num_recipients=count($recipients);
$subject="$senders_name has sent you some of their favorite sites.";
$body_of_email="$senders_name ($senders_email) has sent you some of their favorite links.\n
$comments\n
$url1
$url2
$url3\n
Enjoy!"
;
$additional_headers="From: $senders_email\n";
for(
$i=0; $i<$num_recipients; $i++){
if(
mail($recipients[$i], $subject, $body_of_email, $additional_headers)){
}else{
print(
"Emails not sent, check php code and try again.");
}
}
}else{
print(
"One of your friends emails is not valid, please try again.");
}
print(
"Emails Sent, Send More?");
}else{
print(
"$senders_email is not a valid email address, please try again.");
}
}
?>

<h1>Share some URL's with your friends</h1>
Fill out the form below to send your favorite links to 3 friends.
<FORM METHOD="POST" ACTION="<? $PHP_self ?>">
<input type="hidden" name="action" value="true">
<table cellpadding="5"><tr><td>
Your name:</td><td>
<input type="text" name="senders_name" size="25"></td></tr><tr><td>
Your e-mail:</td><td>
<input type="text" name="senders_email" size="35"></td></tr><tr><td>
Friend 1's e-mail:</td><td>
<input type="text" name="friend1_email" size="35"></td></tr><tr><td>
Friend 2's e-mail:</td><td>
<input type="text" name="friend2_email" size="35"></td></tr><tr><td>
Friend 3's e-mail:</td><td>
<input type="text" name="friend3_email" size="35"></td></tr><tr><td>
URL 1:</td><td>
<input type="text" name="url1" size="55"></td></tr><tr><td>
URL 2:</td><td>
<input type="text" name="url2" size="55"></td></tr><tr><td>
URL 3:</td><td>
<input type="text" name="url3" size="55"></td></tr><tr><td>
Comments:</td><td>
<textarea rows="3" cols="35" name="comments"></textarea>
</td></tr></table>
<input type="submit" value="Submit">
</form>

</center>


 

 

View Previous Thread
Print this page Print This Page

View Next Thread

School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store

Advertising | Link To Us | Privacy 
Copyright 2000-2002 Script School Productions / KMR Enterprises 
No part of this website may be reproduced, copied and/or distributed in any medium 
without express written permission