PHP - Email System Not Working.
For some reason my email system isnt working, but no errors are showing up and i cant seem to find a syntax error. I need some fresh eyes to help to solve this...
Code: [Select] <?php if(isset($_POST['PersonName'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "j.hopley@2008.ljmu.ac.uk"; $email_subject = "An email from your blog."; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['PersonName']) || !isset($_POST['PersomComment']) || !isset($_POST['PersonEmail']) || !isset($_POST['PersonNumber'])) { died('We are sorry, but there appears to be a problem with the form you submitted. One or more fields were empty or contained invailid charicters.'); } $person_name = $_POST['PersonName']; // required $person_comment = $_POST['PersomComment']; // required $person_email = $_POST['PersonEmail']; // required $person_number = $_POST['PersonNumber']; // not required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$person_email)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$person_name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } if(strlen($person_comment) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($person_name)."\n"; $email_message .= "Email: ".clean_string($person_email)."\n"; $email_message .= "Telephone: ".clean_string($person_number)."\n"; $email_message .= "Comments: ".clean_string($person_comment)."\n"; // create email headers $headers = 'From: '.$person_email."\r\n". 'Reply-To: '.$person_email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); } ?> Similar TutorialsI have database table EMAIL[e_id,receiver_email,sender_email,email_Subject,date_time,Text_body] i have displayed sender_email,Email_subject,Date_time in html table by using select sender_email,Email_subject,Date_time from email where receiver_email=$current _user i need to open email_body by clicking the sender_email problem is that how can i get value of first cell of table in the same row by clicking any other column or if you have alternative as yahoo displayes all emails received in inbox by clicking any sender it opens that specific email For my A level ICT i need to create a PHP newsletter email system for which people can sign up from one page and then a admin can log in and send out the email to the people that have signed up. My problem is i also need to attach a PDF to these emails, however i cant work out how to add this into the scripts i have for the newsletter system. Even my teacher cant help me , please can someone help me . The code i have is below. admin.php <?php //load configuration require("config.php"); //connect to database @mysql_connect($db_server,$db_user,$db_password) or die("Database server connection failed. Check variables \$db_server, \$db_user and \$db_password in config.php"); @mysql_select_db($db_name) or die("Selecting database failed. Check variable \$db_name in config.php"); //print header echo $header; ?> <h1><?php echo $title; ?> - Administration</h1> <hr> <?php $pwd = $_GET["pwd"]; //simple login if(isset($pwd) && ($pwd == $password)){ $submit = $_POST["submit"]; $submit_newsletter = $_POST["submit_newsletter"]; $del = $_GET["del"]; //insert new address if(isset($submit)){ $name = $_POST["name"]; $email = $_POST["email"]; @mysql_query("INSERT INTO $db_table (email,name) VALUES ('$email','$name');"); //error occurred if(@mysql_error()){ ?><p>Inserting entry failed: <?php echo @mysql_error(); ?></p> <p><a href="javascript&#058;history.back();">Click here to go back.</a></p><?php //successful }else{ ?><p>Entry has been inserted successfully. <a href="admin.php?pwd=<?php echo $pwd; ?>">Click here to continue.</a></p><?php } //delete an entry }else if(isset($del)){ @mysql_query("DELETE FROM $db_table WHERE id=$del;"); //error occurred if(@mysql_error()){ ?><p>Deleting entry failed: <?php echo @mysql_error(); ?></p> <p><a href="javascript&#058;history.back();">Click here to go back.</a></p><?php //successful }else{ ?><p>Entry has been deleted successfully. <a href="admin.php?pwd=<?php echo $pwd; ?>">Click here to continue.</a></p><?php } //send newsletter }else if(isset($submit_newsletter)){ $sent = 0; $result = @mysql_query("SELECT name,email FROM $db_table ORDER BY email ASC;"); $subject = $_POST["subject"]; $message = $_POST["message"]; ?><p>Sending emails to ...</p> <ul><?php //send emails one by one while($row=@mysql_fetch_array($result)){ $name = $row["name"]; $email = $row["email"]; ?><li><?php echo $name; ?> (<?php echo $email; ?>) ... <?php if(@mail($email,$subject,$message,"From: $admin <$admin>\n")){ ?>sent<?php $sent++; }else{ ?>failed<?php } ?></li><?php } ?></ul> <p><strong><?php echo $sent; ?> emails sent.</strong> <a href="admin.php?pwd=<?php echo $pwd; ?>">Click here to continue.</a></p><?php //print forms }else{ ?><h2>Send newsletter</h2> <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>?pwd=<?php echo $pwd; ?>"> <table> <tr> <td>Subject:</td> <td><input type="text" name="subject" class="fixedwidth"></td> </tr> <tr> <td valign="top">Message:</td> <td><textarea name="message" cols="60" rows="20" class="fixedwidth"><?php echo $signature; ?></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit_newsletter" value="Send"></td> </tr> </table> </form> <h2>Add an email address</h2> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>?pwd=<?php echo $pwd; ?>" method="post"> <table> <tr> <td>Name:</td> <td><input type="text" name="name" value="" maxlength="255"></td> </tr> <tr> <td>Email address:</td> <td><input type="text" name="email" value="" maxlength="255"></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="Submit"></td> </tr> </table> </form> <h2>Email addresses</h2> <table cellpadding="5" cellspacing="2"> <tr class="header"> <td><strong>Name</strong></td> <td><strong>Email address</strong></td> <td> </td> </tr> <?php $result = @mysql_query("SELECT * FROM $db_table ORDER BY email ASC;"); $colored = false; while($row=@mysql_fetch_array($result)){ $colored = !$colored; ?><tr<?php if($colored){ ?> class="colored"<?php } ?>> <td width="200"><?php echo $row["name"]; ?></td> <td width="200"><?php echo $row["email"]; ?></td> <td><a href="<?php echo $_SERVER["PHP_SELF"]; ?>?pwd=<?php echo $pwd; ?>&del=<?php echo $row["id"]; ?>">remove</a></td> </tr><?php } ?> </table> <?php } }else{ //print login form echo $login; } //print link to news ?><p align="right"><a href="index.php">Newsletter</a></p><?php //print footer echo $footer; //close database connection @mysql_close(); ?> config.php <?php /* ######################## DATABASE ######################## */ // Database server $db_server = "localhost"; // Database name $db_name = "zpwebsi1_news"; // Database username $db_user = "zpwebsi1_zac"; // Database password $db_password = "powell"; // Database table to store news // (will be created automatically) $db_table = "easy_newsletter"; /* ##################### CONFIGURATION ###################### */ // Complete URL of the script // (begins with http://, ends with slash) $url = "http://www.charsfieldthreehorseshoes.co.uk/alemail.html"; // Password for the administration $password = "admin"; // Administrator email address (will be used as sender of // the newsletter emails) $admin = "zac@zpwebsite.com"; // Title (will be displayed in the browser's header $title = "Ale Mail"; // Signature (will be inserted when creating a fresh // newsletter but can be changed before submitting) $signature = "\n\n\n\n\n---------------------\nYou receive this email because you have registered with our newsletter $title. Click the following link to unsubscribe: $url"; /* ######################### LAYOUT ######################### */ // Header to be used on each page $header = <<<EOT <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="style.css" rel="stylesheet" type="text/css"> <title>$title</title> </head> <body> EOT; // Footer to be used on each page $footer = <<<EOT </body> </html> EOT; // Login form $login = <<<EOT <form action="admin.php" method="get"> Password: <input name="pwd" type="password"> <input type="submit" value="Login"> </form> EOT; ?> And index.php <?php //load configuration require("config.php"); //print header echo $header; ?> <h1><?php echo $title; ?></h1> <hr> <?php //form submitted if(isset($_POST["submit"])){ //connect to database @mysql_connect($db_server,$db_user,$db_password) or die("Database server connection failed. Check variables \$db_server, \$db_user and \$db_password in config.php"); @mysql_select_db($db_name) or die("Selecting database failed. Check variable \$db_name in config.php"); $name = $_POST["name"]; $email = $_POST["email"]; //subscribe if($_POST["action"]=="subscribe"){ //check if name is long enough if(strlen($name)<3){ ?><p>Name must consist of at least 3 characters.</p><?php //check if email is valid }else if(!eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$",$email)){ ?><p>Email address is not valid.</p><?php //check if email already exists }else if(@mysql_num_rows(@mysql_query("SELECT id FROM $db_table WHERE email='$email';"))){ ?><p>Email address exists already.</p><?php //insert values }else{ @mysql_query("INSERT INTO $db_table (email,name) VALUES ('$email','$name');"); //error occurred if(@mysql_error()){ ?><p>An unknown error occurred. Please try again later.</p><?php //successful }else{ ?><p>Subscription was successful. Thank you!</p><?php } } //unsubscribe }else{ @mysql_query("DELETE FROM $db_table WHERE email='$email';"); //error occurred if(@mysql_error()){ ?><p>An unknown error occurred. Please try again later.</p><?php //email not found }else if(@mysql_affected_rows()==0){ ?><p>Email address not found.</p><?php //successful }else{ ?><p>You have unsubscribed successfully!</p><?php } } } ?> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"> <table> <tr> <td>Your name:</td> <td><input type="text" name="name" value="" maxlength="255"></td> </tr> <tr> <td>Your email address:</td> <td><input type="text" name="email" value="" maxlength="255"></td> </tr> <tr> <td> </td> <td><input type="radio" name="action" value="subscribe" id="action_subscribe" checked> <label for="action_subscribe">subscribe</label> <input type="radio" name="action" value="unsubscribe" id="action_unsubscribe"> <label for="action_unsubscribe">unsubscribe</label></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="Submit"></td> </tr> </table> </form> <p align="right"><a href="admin.php">Administration</a></p> <?php //print footer echo $footer; //close database connection @mysql_close(); ?> Hi guys, I am thinking of create an free email system by sending an messages using with a username. Would I have to store the messages via in mysql? If I can do that, then I just curious that how would a user delete their messages if their messages is display on php page? What method would I have to use? Hello. I've been having trouble with this trade system not working(my friend made it). Most of it is functioning properly, except the part where it's supposed to show your partners pokemon box. Here is the code:
<?php require_once("top_header.php"); if(!isset($_GET["p"]) && !isset($_GET["id"]) && !isset($_GET["submit"])) { ?> <form action="trading.php" method="get"> Please enter the ID of the person you would like to trade:<br /> <input type="text" name="p" /><br /> <input type="submit" value="Continue!" /><br /> </form> <table width=100%> <tr> <td class="header">Trade Partners:</td> <td class="header">Open Trades:</td> </tr> <?php $check1 = "SELECT trade_id, starter_id FROM trades WHERE partner_id = $id AND status = 0"; $check2 = mysql_query($check1); while($row = mysql_fetch_array($check2)) { $ass = mysql_fetch_array(mysql_query("SELECT username FROM users WHERE id = {$row["starter_id"]}")); echo "<tr>"; echo "<td class=into>"; echo $ass["username"]; echo "</td>"; echo "<td class=into>"; echo "<a href=trading.php?id={$row["trade_id"]}>View Trade!</a>"; echo "</td>"; echo "</tr>"; } ?> <tr> <td class="header">Created To:</td> <td class="header">Options:</td> </tr> <?php $check1 = "SELECT trade_id, partner_id FROM trades WHERE starter_id = $id AND status = 0"; $check2 = mysql_query($check1); while($row = mysql_fetch_array($check2)) { $ass = mysql_fetch_array(mysql_query("SELECT username FROM users WHERE id = {$row["partner_id"]}")); echo "<tr>"; echo "<td class=into>"; echo $ass["username"]; echo "</td>"; echo "<td class=into>"; echo "<a href=delete.php?id={$row["trade_id"]}>Delete Trade!</a>"; echo "</td>"; echo "</tr>"; } ?> </table> <?php } else if(isset($_GET["p"])) { $check = mysql_num_rows(mysql_query("SELECT username FROM users WHERE id = ".$_GET['p']."")); if($check <= 0) { echo "Please do not try to trade non existant users!"; include('bottom_layout.php'); die(); } ?> <form action="trading.php?submit" method="post"> <b>Your Pokemon:</b><br> <select width="100px" size=15 name="starter[]" multiple="multiple"> <option value="0" selected>None</option> <?php $query = mysql_query("SELECT id, nickname, level FROM pokemon WHERE owner_id= $id AND slot = 7"); while($info = mysql_fetch_assoc($query)) { ?> <option value="<?php echo $info["id"] ?>"><?php echo $info["nickname"] ?> level:<?php echo $info["level"]?></option> <?php } ?> </select> <br><br><br> <b>Partners Pokemon</b><br> <select width="100px" size=15 name="partner[]" multiple="multiple"> <option value="0" selected>None</option> <?php $p = htmlentities($_GET["p"]); $sql = "SELECT id, gender, pokedex_id, type, level FROM pokemon WHERE owner_id = $p AND slot = 7 AND status = 1"; $starter_pokemon = mysql_query($sql); while($row = mysql_fetch_assoc($starter_pokemon)) { $name = mysql_fetch_assoc(mysql_query("SELECT name FROM pokedex WHERE id={$row["pokedex_id"]}")); $type = mysql_fetch_assoc(mysql_query("SELECT name FROM types WHERE id={$row["type"]}")); $name = $type["name"].$name["name"]; ?> <option value="<?php echo $info["id"] ?>"><?php echo $info["nickname"] ?> level:<?php echo $info["level"]?></option> <?php } ?> </select><br /> <input type="submit" value="Send Trade!" /> <input type="hidden" name="p_id" value="<?php echo $_GET["p"];?>" /> </form> <?php } else if(isset($_GET["submit"])) { $status = 0; $partner = mysql_real_escape_string($_POST["p_id"]); foreach($_POST["starter"] as $pokemon) { $pokemon = mysql_real_escape_string($pokemon); $result = mysql_query("SELECT id FROM pokemon WHERE owner_id = $id AND id = $pokemon"); if(mysql_num_rows($result) == 0 && $pokemon != 0) { $status = 5; } } foreach($_POST["partner"] as $pokemon) { $pokemon = mysql_real_escape_string($pokemon); $result = mysql_query("SELECT id FROM pokemon WHERE owner_id = $partner AND id = $pokemon"); if(mysql_num_rows($result) == 0 && $pokemon != 0) { $status = 5; } } $starter_pokemon = json_encode($_POST["starter"]); $partner_pokemon = json_encode($_POST["partner"]); if($starter_pokemon == "[\"0\"]" && $partner_pokemon == "[\"0\"]") { echo "Sorry, one of you has to be trading something!"; } $sql = "INSERT INTO trades (starter_id, starter_pokemon, partner_id, partner_pokemon, status) VALUES ($id, '".mysql_real_escape_string($starter_pokemon)."', $partner, '".mysql_real_escape_string($partner_pokemon)."', $status)"; mysql_query($sql); echo "Trade created!"; } else if(isset($_GET["id"])) { $trade = mysql_real_escape_string($_GET["id"]); $sql = "SELECT * FROM trades WHERE trade_id = $trade"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $starter_pokemon = json_decode($row["starter_pokemon"]); $partner_pokemon = json_decode($row["partner_pokemon"]); echo "<h3>You are Trading:</h3>"; foreach($partner_pokemon as $pokeid) { $pokeinfo = mysql_fetch_assoc(mysql_query("SELECT pokedex_id, gender, type, level FROM pokemon WHERE id = $pokeid")); $name = mysql_fetch_assoc(mysql_query("SELECT name FROM pokedex WHERE id = {$pokeinfo["pokedex_id"]}")); $type = mysql_fetch_assoc(mysql_query("SELECT name FROM types WHERE id = {$pokeinfo["type"]}")); echo $type["name"].$name["name"]." ({$pokeinfo["gender"]}) (Level:{$pokeinfo["level"]})<br />"; } echo "<h3>Your Partner is Trading:</h3>"; foreach($starter_pokemon as $pokeid) { $pokeinfo = mysql_fetch_assoc(mysql_query("SELECT pokedex_id, gender, type, level FROM pokemon WHERE id = $pokeid")); $name = mysql_fetch_assoc(mysql_query("SELECT name FROM pokedex WHERE id = {$pokeinfo["pokedex_id"]}")); $type = mysql_fetch_assoc(mysql_query("SELECT name FROM types WHERE id = {$pokeinfo["type"]}")); echo $type["name"].$name["name"]."({$pokeinfo["gender"]}) (Level:{$pokeinfo["level"]})<br />"; } ?> <br><br> <a href=complete.php?id=<?php echo $row['trade_id']; ?>>Complete the trade!</a><br><a href=delete.php?id=<?php echo $row['trade_id']; ?>>Delete the trade!</a> </table> <?php } require_once("bottom_layout.php"); ?> Hi, I made a login/register system and it was working fine, but now I seem to have broken it and I'm scratching my head as to why. I think it's something to do with the $_SESSION array, the error happens from going from the login.php page to members.php, I log in successfully, but when I get to the members page it says "you must be logged in". index.php has the form to login or a link to register.php to make an account Code: [Select] <?php session_start(); ?> <html> <head> <title>Lincs Crusade | Login page.</title> </head> <body> <form action="login.php" method="POST"> Username: <input type="text" name="username"><br /> Password: <input type="password" name="password"><br /> <input type="submit" value="Login"> </form> <a href="register.php">Click here to register!</a> </body> </html> The register.php page Code: [Select] <?php session_start(); echo "<h2>Register</h2>"; $submit = $_POST['submit']; $username = strip_tags($_POST['username']); $password = strip_tags($_POST['password']); $repeatpassword = strip_tags($_POST['repeatpassword']); $email = $_POST['email']; $date = date("Y-m-d"); if ($submit) { if ($username&&$password&&$repeatpassword&&$email) { if ($password==$repeatpassword) { if (strlen($username)>65) { echo "Length of username is too long!"; } elseif (strlen($email)>100) { echo "Length of email is too long!"; } elseif (strlen($password)>65||strlen($password)<8) { echo "Password must be between 8 and 65 characters long!"; } else { include('functions.php'); echo "All fields were accepted! "; $password = md5($password); $repeatpassword = ($repeatpassword); $email = md5($email); connect(); mysql_query(" INSERT INTO users VALUES ('','$username','$password','$email','$date') ") or die("Could not insert values into <em>users</em> table!"); mysql_query(" INSERT INTO stats VALUES ('$username',10,10,0,1) ") or die("Could not insert values into <em>stats</em> table!"); $_SESSION['username'] == $username; die("You have been registered! Please return to <a href=\"index.php\">homepage</a> and login."); } } else { echo "Your passwords do not match!"; } } else { echo "Please fill in <em>all</em> fields!"; } } ?> <html> <head> <title>Lincs Crusade | Register an Account.</title> </head> <body> <form action="register.php" method="POST"> <p>Your username:</p> <p>Note: Do not use your real name.</p> <input type="text" name="username" value="<?php echo $username ?>"/>= <p>Choose a password:</p> <input type="password" name="password" /> <p>Please repeat password:</p> <input type="password" name="repeatpassword" /> <p>Your student email:</p> <p>Note: This is only used for recovering a lost or forgotten password.</p> <input type="text" name="email" /><br /> <input type="submit" value="Register" name="submit" /> <p> Note: Your password and email are md5 encrypted. This means neither I (the author) or anyone else will be able to view your information<br /> in plain text. For example, your password or email will look something like this "534b44a19bf18d20b71ecc4eb77c572f" once it has been encrypted. </p> </form> </body> </html> The login.php page that process the form data to access members.php page Code: [Select] <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { include('functions.php'); connect(); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrow = mysql_num_rows($query); if ($numrow!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&md5($password)==$dbpassword) { echo "You're in! - <a href=\"members.php\">Proceed to the members page</a>"; $_SESSION['username'] == $username; } else { echo "Incorrect password!"; } } else { die ("That user doesn't exist,<a href=\"register.php\">please register an account</a>"); } } else { die("Please enter a username and password!"); } ?> The members.php page Code: [Select] <?php session_start(); ?> <html> <head> <title>Lincs Crusade | Members page.</title> </head> <body> <?php if ($_SESSION['username']) { echo "Welcome," .$_SESSION['username']. "!<br />"; echo "<a href=\"stats.php\">View your stats.</a>"; } else { die ("You must be logged in."); } ?> </body> </html> and this is what is in the functions.php file Code: [Select] <?php function connect() { mysql_connect("localhost","root","password") or die ("Unable to connect"); mysql_select_db("database") or die ("Unable to find database"); } ?> Thanks for your help. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=348317.0 Hi im pretty new to php but I was following a tutorial for a commenting system and implemented it onto my blog page. Anyway the problem I have is that as you go down the page each blog post displays its own comments + the comments for the posts above it. I have checked the database and the data seems to link the correct comments to the correct posts so I am confused to why this is happening. I have looked over my code and cant seem to find a problem (probably because I suck!). Here is the code for the blog page... Code: [Select] <?php include_once ("scripts/checkuserlog.php"); include_once ("scripts/connectToMysql.php"); include_once ("functions/agoTime.php"); $myObject = new convertToAgo; $username = ''; $errorMsg = ''; $successMsg = ''; $date = date("m.d.y"); if (isset($_GET['id'])) { $id = preg_replace('#[^0-9]#i', '', $_GET['id']); } else if (isset($_SESSION['idx'])) { $id = $logOptions_id; } else { header("location: index.php"); exit(); } $id = preg_replace('#[^0-9]#i', '', $id); $sql = mysql_query("SELECT * FROM members WHERE id='$id' LIMIT 1"); $existCount = mysql_num_rows($sql); if ($existCount == 0) { header("location: index.php?msg=user_does_not_exist"); exit(); } while($row = mysql_fetch_array($sql)){ $username = $row["username"]; } if(isset($_POST['workoutName'])){ $workoutName = $_POST['workoutName']; $workoutDescription = $_POST['workoutDescription']; if ((!$workoutName) || (!$workoutDescription)) { $errorMsg = 'Please fill in both fields'; } else { $insertBlog = mysql_query("INSERT INTO blog (userid, workoutName, workoutDescription, datetime) VALUES ('$id', '$workoutName', '$workoutDescription', now())") or die(mysql_error()); if ($insertBlog){ $successMsg = '<span class="errorMsg">Workout blogged successfully</span>'; } else { $errorMsg = '<span class="errorMsg">Problems arose during the information exchange, please try again later.</span>'; } } } $getBlog = mysql_query("SELECT * FROM blog WHERE userid='$id' ORDER BY id DESC"); $blogEntries = mysql_num_rows($getBlog); if($blogEntries < 1){ $blogDisplay = '<span class="blogName">' .$username. ' has not blogged a workout yet</span>'; } else { while($row = mysql_fetch_array($getBlog)){ $blogEntryId = $row["id"]; $sql_comment = mysql_query("SELECT * FROM blog_comments WHERE post_id='$blogEntryId' ORDER BY id ASC"); $countComment = mysql_num_rows($sql_comment); if($countComment > 0){ while($row2 = mysql_fetch_array($sql_comment)){ $comment_user_id = $row2["comment_user_id"]; $sql_comment_username = mysql_query("SELECT username FROM members WHERE id='$comment_user_id' LIMIT 1"); while($row3 = mysql_fetch_array($sql_comment_username)){ $comment_username = $row3["username"];} $post_id = $row2["post_id"]; $commentBody = $row2["comment_body"]; $commentDate = $row2["comment_date"]; $displayCommentList .= '<div>' .$comment_username. ' - ' .$commentBody. ' - ' .$commentDate. '</div>'; } } else { $displayCommentList = ''; } $workoutName = $row["workoutName"]; $workoutDescription = $row["workoutDescription"]; $blogDate = $row["datetime"]; $convertedTime = ($myObject -> convert_datetime($blogDate)); $blogDate = ($myObject -> makeAgo($convertedTime)); $blogDisplay .= '<table width="950px"><tr bgcolor="#DBE4FD"><td><span class="blogName">' .$workoutName. '</span> » <span class="blogDate">' .$blogDate. '</span></td></tr> <tr bgcolor="#F1F4FE"><td><span class="blackText">' .$workoutDescription. '</span></td></tr> <tr bgcolor="#DBE4FD" valign="top"><td>' .$displayCommentList. '</td></tr> <div id="new_comment' .$blogEntryId. '" style="display:none"></div> <tr><td><textarea id="comment' .$blogEntryId. '"></textarea><input type="submit" value="Comment" onclick="javascript:SendComment(\''.$blogEntryId.'\');" /></td></tr>'; if(isset($_SESSION['id'])&&$_SESSION['id']==$id){ $blogDisplay .= '<tr bgcolor="#DBE4FD"><td><a href="editBlogPost.php?id=' .$blogEntryId. '"><span class="blackText">Edit Post</span></a> &#8211; <span class="blackText">Delete Post</span></td></tr></table><br /><br />'; } } } if(isset($_POST['deleteButton'])){ $deleteBlog = mysql_query("DELETE FROM blog WHERE id='$blogEntryId'"); if($deleteBlog){ $successMsg = 'Blog entry deleted successfully'; } else { $errorMsg = 'Could not process your request, please try again later'; } } ?> <?php if (isset($_SESSION['id'])&&$_SESSION['id']==$id) { $blogForm = '<table bgcolor="#DBE4FD" width="950px"> <form action="member_blog.php" method="post" enctype="multipart/form-data"> <tr> <td width="200px"><span class="blackText">Workout Name:</span></td><td width="650px"><input name="workoutName" type="text" id="workoutName" /> <span class="blackText">Date: ' .$date. '</span></td></tr> <tr> <td><span class="blackText">Workout Description:</span></td><td><textarea name="workoutDescription" cols="75" rows="10" id="workoutDescription" /></textarea></td></tr> <tr><td><input name="submitBlog" id="submit" type="submit" value="Blog!" /></td><td><span class="errorMsg">' .$errorMsg. '' .$successMsg. '</span></td> </tr> </form> </table>'; } else { $blogForm = ''; } ?> <!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><?php echo ("$username"); ?>'s Blog</title> <link href="style/layout.css" rel="stylesheet" type="text/css" /> <link href="style/main.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> function SendComment(blogEntryId){ var comment_txt = $("#comment"+blogEntryId).val(); if(comment_txt == ""){ alert("Please enter a comment"); } else { $.post("scripts/blogComment.php", {comment: comment_txt, blogId: blogEntryId} ,function(data){ $("#new_comment"+blogEntryId).html(data); $("#new_comment"+blogEntryId).slideDown(300); }); } } </script> </head> <body> <div id="container"> <?php include_once ("bannerFiles/bannerTemplate.php"); ?> <?php include_once ("bannerFiles/bannerMenu.php"); ?><br /> <div id="content"> <span class="profileUsername"><?php echo ("$username"); ?>'s Workout Blog</span><br /><br /> <?php echo ("$blogDisplay"); ?><br /><br /> <?php echo ("$blogForm"); ?> </div><br /><br /> <?php include_once ("footerFiles/footerTemplate.php"); ?> </div> </body> </html> ...and here is the code for the blogComment.php page Code: [Select] <?php session_start(); include_once ("connectToMysql.php"); if(isset($_POST['comment'])){ $comment = $_POST['comment']; $blogId = $_POST['blogId']; $comment_user_id = $_SESSION['id']; $username = $_SESSION['username']; $sql = mysql_query("INSERT INTO blog_comments (comment_body, post_id, comment_user_id, comment_date) VALUES ('$comment', '$blogId', '$comment_user_id', now())"); echo '<div>' .$username. ' - ' .$comment. ' - Just Now</div>'; } else { echo "Failure"; } ?> Thanks in advance for any help Hi all, I'm trying to add a section where it verifies that the email address is active in my register code. My code below is it checking the dnsrr, and if it is not real, I have it die and an error message appears. However, I am getting the error message all the time, whether I am sure the email is working or not. First I declared my email variable ($email), and then after the code below I of course insert the new data in to the database. I'm doing this over my localhost, so is that why it can't verify emails? Or am I setting this up wrong? Code: [Select] <?php $email = trim($_POST['email']); if (False !== strpos($email, '@')) die("Please type in an email address.<br><br><a href=register.php>Continue</a>"); if(!@checkdnsrr($mailDomain,'MX')) die("Not real email address. Please try again.<br><br> <a href=register.php>Continue</a>"); ?> Hi all I'm trying to send an automated email of a zip file. However it seems to be just reading the files into the body of the mail rather than attaching a single zip archive containing several files. I receive the mails, but I effectively want a blank message body with a zip file attached. Please see code below, any ideas why this is not working. I'm a bit of a newbie and never used this before so any pointers would be good. <?php //Send Zip file as attachment //Set Email and attachment details $to = "me@123.com"; $from = "Visionnet <DO_NOT_REPLY>"; $subject = "Subject"; $message = "Please see attached file"; $fileatt = "wiki_zip.zip"; $fileatt_type = "application/zip"; $fileatt_name = "wiki_zip.zip"; //Read in the attachment $file=fopen($fileatt,'rb'); $data=fread($file,filesize( $fileatt)); fclose($file); //Add the MIME content $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the Headers for file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $message = "This is a multipart message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; //Base64 encode file data $data = chunk_split(base64_encode($data)); //Add attachment to message $message .= "--{mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; //Send message $ok = @mail($to, $subject, $message, $headers, "$from"); if($ok) { echo "mail sent"; } else { echo "mail failed"; } ?> :'(I've already had two strikes on my efforts at questions, so I'm planning on at least fouling this one away.... The attached, running(!) PHP email generating program allows me to input info, but then generates the following error message after filling out the form: from Yahoo website: "Sorry, the page you requested was not found. "Additionally, a 410 Gone error was encountered while trying to handle the request." Here is the questionable code: <html> <body> <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "debbiekn777@yahoo.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> </body> </html> Please, where do I go from here? Trying to be different from the last kid, Yshua This is completely different code than my change password script thread. This is not double posting. Whenever I use this script to change my email, it just changes the email to nothing (blank). What could be wrong with it? Help is hugely appreciated. I know you don't have to use your valuable time to help me. <?php // I removed the connect to db part session_start(); $username = $_SESSION['username']; $email = $_POST['email']; $newemail = $_POST['newemail']; $confirmnewemail = $_POST['confirmnewemail']; $result = mysql_query("SELECT email FROM members WHERE username='$username'"); if($email!= mysql_result($result, 0)) { echo "The email address you entered is incorrect."; } if($newemail==$confirmnewemail) $sql=mysql_query("UPDATE members SET email='$newemail' where username='$username'"); if($sql) { echo "You have successfully changed your email address."; } else { echo "The new email and confirm new email fields were different."; } ?> I've created a script to remove duplicate emails and it works perfectly up to about 20k. After that it just stops with no error code. I'm baffled. I've increased the max_execution_time to 2 hours even though this script just takes a few minutes. <?PHP function validElement($element) { return strlen($element) > 1; } function in_iarray($str, $a){ foreach($a as $v){ if(strcasecmp($str, $v)==0){return true;} } return false; } remove_duplicates(); } //Remove more duplicates from list function array_iunique($a){ $n = array(); foreach($a as $k=>$v){ if(!in_iarray($v, $n)){ echo $v; $n[$k]=$v;} } return $n; } //Remove duplicates from list function remove_duplicates() { $p = 0; while ($p != 1) { $rawemaillist = array_values(array_filter($rawemaillist, "validElement")); $p = 1; } $initial = count($rawemaillist); $k = 0; while ($k != 1) { $rawemaillist = array_iunique($rawemaillist); $k = 1; } ?> The script works fine - but only up to around 20 k - which leads me to believe its a server setting issue. Is there something in the php.ini file I should or otherwise a setting that I should be looking at to change??? hi need some help, the following PHP script on my website has stopped working without me editing it : <?php if(isset($_POST['email'])) { // CHANGE THE TWO LINES BELOW $email_to = "contact@myemail.com"; $email_subject = "enquiry"; function died($error) { // your error code can go here echo "Sorry, but errors were found in the form you submitted.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['full_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['full_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br /><br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The Full Name you entered does not appear to be valid.<br /><br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Full Name: ".clean_string($first_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- place your own success html below --> Thank you for contacting us, we will be in touch soon. <?php } die(); ?> which was working with the following form: <form name="htmlform" method="post" action="contact_uk.php"> <table style="background-color:whitesmoke; border:1px solid black; border-collapse:collapse" ;="" width="542px"> <tbody><tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="top"> <label for="first_name">Full Name *</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <input name="full_name" maxlength="50" size="30" type="text"> </td> </tr> <tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="top"> <label for="email">Email Address *</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <input name="email" maxlength="80" size="30" type="text"> </td> </tr> <tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="top"> <label for="telephone">Telephone Number</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <input name="telephone" maxlength="30" size="30" type="text"> </td> </tr> <tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="middle"> <label for="comments">Message *</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <textarea name="comments" maxlength="1000" cols="22" rows="6"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input value="Submit" type="submit"> </td> </tr> </tbody></table> </form> Now, I have tried the following test script found here (http://myphpform.com...not-working.php) and it does not work : <?php $from = "contact@myemail.com"; $headers = "From:" . $from; echo mail ("admin@awardspace.com" ,"testmailfunction" , "Oj",$headers); ?> so I have then contacted my Host which replied as follows: when you send emails by scripts and it is that our SMTP server requires authentication in order to send emails out. By using one of the emails that exist in the control panel as a sender/"from" header, you will be able to authenticate yourself and the SMTP server will send without problems. and provided this script, which works: <? $from = "From: You <contact@myemail.com>"; $to = "anymail@hotmail.com"; $subject = "Hi2! "; $body = "TEST"; if(mail($to,$subject,$body,$from)) echo "MAIL - OK"; else echo "MAIL FAILED"; ?> so can someone help me fix the code in the first quote I posted based on this last working one ? A few things maybe worth a mention: - previously, about a few weeks back, this form (first two quotes) was working perfectly as I've posted it and sending emails to my hotmail account without a hitch... - in the quotes "contact@myemail.com" is actually the domain email I have with the host thanks to anyone kind enough to help out... <form action="form-to-email.php" method="post" enctype="text/plain" class="form"> <p class="name"> <i class="icon-user"></i> <input type="text" name="name" id="name" /> <label for="name">Name</label> </p> <p class="email"> <i class="icon-envelope"></i><span id="sprytextfield1"> <input type="text" name="email" id="email" /> </span> <label for="email">E-mail</label> </p> <p class="phone"><i class="icon-phone-sign"></i> <input type="text" name="phone" id="phone" /> <label for="web">Phone</label> </p> <p class="text"><span id="sprytextarea1"> <textarea name="text"></textarea> <span class="textareaRequiredMsg">A value is required.</span></span></p> <p class="submit"> <input type="submit" name="submit" id="submit" value="Send message"> </p> </form>The form is located in index.html and separate page is form-to-email.php. Do I need to link them <link href=>, <link rel=> or the files just need to be in the same folder? <?php if(!isset($_POST['submit'])) { //This page should not be accessed directly. Need to submit the form. echo "error; you need to submit the form!"; } $name = $_POST['name']; $visitor_email = $_POST['email']; $message = $_POST['message']; //Validate first if(empty($name)||empty($visitor_email)) { echo "Name and email are mandatory!"; exit; } if(IsInjected($visitor_email)) { echo "Bad email value!"; exit; } $email_from = '$visitor_email \r\n"'; $email_subject = "New Form submission"; $email_body = "You have received a new message from the user $name.\n". "Here is the message:\n $message". $to = "2d2f@gmail.com";//<== update the email address $headers = "From: $email_from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; //Send the email! mail($to,$email_subject,$email_body,$headers); //done. redirect to thank-you page. header('Location: thank-you.html'); i have a form for sending email with cc and bcc bud when try to send it.. it shows an error..
please see it here
http://www.pstwist.com/send-cc-email/
Attached Files
123.zip 2.28KB
0 downloads What am I doing wrong? All I want is a flash and php email form working. At best i get the elements emailed surrounded by all the html formatiing tags makign it impossible to head or only a few (ie messahe and phone) show up in email sent or more often nothign gets sent at all. In the flash filn I have a send button with Code: [Select] onClipEvent(data){ _root.nextFrame(); } actioned on the form movie in flash And Code: [Select] on(release){ form.loadVariables("email_send.php", "POST"); } script on the send button. The movie where the form is places has 5 fields made with input text with Instant names: Inp_Name Inp_Department Inp_Email Inp_Phone Inp_Message their variables are; name dept phone message Also in the properties theya re all set to HTML rednering is set to off and the webssite is www.chriscreativity.com Why does it not work at all and if it does how do I loose the htmal formings crap and get it to work please Code: [Select] <strong><?php /* --------------------------- php and flash contact form. by www.MacromediaHelp.com --------------------------- Note: most servers require that one of the emails (sender or receiver) to be an email hosted by same server, so make sure your email (on last line of this file) is one hosted on same server. --------------------------- */ $sendTo = "chris.bruneluni@yahoo.co.uk"; $subject = "Message from chriscreativity.com"; // read the variables form the string, (this is not needed with some servers). $headers = $_POST["name"] . $_POST["dept"] . $_POST["email"] . $_POST["phone"]; $message = $_POST["message"]; mail($sendTo, $subject, $message, $headers); ?></strong> [attachment deleted by admin] hello dear PHP-Fans - greetings to you - and a happy new year!! i set up a WAMP-System on my openSuse 11.4 system. In order to learn as much as i can bout PHP i want to do some tests and write some scripts. Well the WAMP is allready up and running. Now i try to give the writing access to the folder mkdir /srv/www/ where the php-scripts should go in... i want to give write permission to all to all files in /srv/www As root I generally: mkdir /srv/www/ chown <webmaster usrername> /srv/www/ /srv/www/ should be readable and traversable by all, but only writeable by it's owner (the user designated as the webmaster.) can i do this like mentioned above,... Love to hear from you greetings db1 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=307745.0 |