PHP - Embeding Variables In Email Messages
How can i embed variables into an email message.
Eg. If i want to add the result of mysql query, would i do somthing similiar to this; mail( "email@domain.co.uk", "Header","$message $result" ); ? Obviously this doesn't work. In fact i get the message from my html form, followed by 'Resource id #2'. Im learning php at the moment. If anyone could help me with this, or point me in the right direction this would be great. Iv'e looked at w3schools but I cant find anything specific like this. mysql_connect("db.hostedresource.com","treesurgery","password here"); mysql_select_db("treesurgery") or die("Unable to select database"); $code = $_GET['postcode']; $message = $_GET['message']; $result = mysql_query("SELECT email FROM treesurgeons WHERE postcode LIKE '%$code%' ORDER BY companyName LIMIT 3") or die(mysql_error()); echo "<h2>Business Names:</h2>"; while ($row = mysql_fetch_array( $result )) { echo " ".$row['email'] . "<br>"; } echo "<br>"; echo $message; mail( "email@domain.co.uk", "Header","$message" ); echo "Thank you for using our mail form."; Similar TutorialsThis is what I'm getting... Notice: Undefined variable: sitetitle in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: ADcode in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: email in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: url in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: charge in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: currency in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: price in /home/vehiclep/public_html/functions.php on line 121 this is functions.php Code: [Select] function sitesets() { $sql = "select * from settings limit 1"; $rs = mysql_query($sql); $row = @mysql_fetch_array($rs); extract($row); $sitesets = array("title"=>$sitetitle, "ADcode"=>$ADcode, "email" => $email, "url" => $url, "charge" => $charge, "currency" => $currency, "price" => $price); return $sitesets; } Ive tried going into phpMyadmin and creating a row and entering the info manualy but it doesnt work. I don't know much about coding so this may be a dumb question but it has me stumped. I hope somebody can tell me what I'm missing here. I have a process that runs in the background, so I don't get to see its output. What I would like to do, is if a error occurs (mysql or php) send me an email with the error message(s), then end the process. Any way I can do this? Right now, I am not sure if any errors occur, but I am thinking that they might be happening. So any way for me to get the error would be awesome! Hi guys, this is my first post, and im needing some help with email and variables in php. when i save this out it works: <?php $test = "hi there"; mail('myemail@mythingy.com.au','test subject', 'This is a test'); ?> but as soon as i add variable into the mix it doesnt work... <?php $email = "myemail@mythingy.com.au"; mail($email,'test subject', 'This is a test'); ?> any clues? Good afternoon everyone, probably just a quick one this one! I have a reg form, and once the user has been added to the database then it is meant to send them an email with their username and password. The email works fine, received as it should, however the place where I am trying to echo variables is blank. For instance Code: [Select] <style type='text/css'> h3 { font-family: Tahoma, Geneva, sans-serif; font-size: 24px; font-style: oblique; color: #00F; } </style> <body> <img src='https://www.buy2earn.co.uk/images/logo.png' width='240' height='100'> <hr> <h3>Welcome to buy2earn.co.uk!</h3> <p> Welcome <?php echo $username:?> just shows Welcome ................... How do I send the variables in the email? Cheers Hello, I am new to PHP and would like to know what I am doing incorrectly. I have designed a login form which contains two variables: the username and the password. So for the username: <input type="hidden" name="email" id="email" value="example_username"> And for the password: <input type="password" name="password" id="password" size="15"> I then created a php script which I want to pass the variables "email" and "password" to the e-mail address: <?php { $message = "$email"; $message2 = "$password"; mail ("email@myserver.com", "Hello", $message, $message2); } ?> This should happen through the command: <action="http://www.myserver.com/myscript.php" method="post"> All I get is a blank email with the subject "Hello". Why are the email and password variables not being passed to my email by the php script? Thanks. Code: [Select] $IP = $_SERVER['REMOTE_ADDR']; $DATE = date("Y-m-d"); $TIME = date("H:i:s"); $NameOfSender = "BLABLABLABALLA"; $email = $fieldnm_3; // use their addy instead of yours $subject = 'ikwerkthuis.be inloggegevens introductie film'; // change subject $text = 'Beste $NameOfSender, Welkom bij ikwerkthuis.be. Hieronder vind U de logingevens voor het bekijken van de introductiefilm: Adres: http://ikwerkthuis.be/index.php/introductie Gebruikersnaam: introductie Paswoord: film2012 %DataOfForm% Wij nemen spoedig contact met u op. Met vriendelijke groeten, Het ikwerkthuis.be team IP: $IP Date: $Date Time: $Time'; // change text mail($email, $subject, $text, 'From: '.$emailadd.''); // send another one out header("Location:$success_page_name"); } ?> How is it possible, in PHP, to display an error message next to a form input text field if a user is attempting to submit a form with empty fields? Moreover, how is it possible to remove the same error message when the user fills in the input field with the required data and/or refreshes the page? I have 2 files that I am working with: application.php and process.php.
application.php mainly has the HTML of the form. I am very new to learning PHP (I started learning it last week) and I have been searching for hours for a clear answer. I have already tried different methods for generating the error message including: using empty(), !isset, $_POST["name"] = "", etc, and have tried using session_start();, $row, echo, print, and other variables to try and display error message on the page, and I have tried using unset();, and = null, to try and remove the error message once the input field has been filled but all to no avail. Either the method I try only half works, or nothing works, and I cannot pinpoint which is the part that is not working. I only have 2 files to work with, and as an example of what I want to do is:
1. If the first name field is empty when the user clicks submit, an error message should appear next to the input. Is this possible with PHP? I placed car-dealer-website, a web application from car-dealer-website.org , in a subdirectory on my host mysite.com/car. Wordpress is public_html (mysite.com). What I am trying to do is embed mysite.com/car in Wordpress. I tried iframe and it is ugly. I looked for a php css options,using a code I found online, it didnt work but I saw hope and think php and css is the solution. What I am asking for is direction on using php and css to embed in Wordpress. I want to write code no plugins. I hope to learn some php coding. Thank you in advance for your suggestions, tutorials, different methods. How can this be written in PHP? Code: [Select] echo '<IMG alt="" src=".$row['id']/thumb.png">'; I think I finally figured out what my problem is! I have this huge login system that I got and I think it's designed so that in order to login it has a popup window come up. Well I want embed this page so the user can login right their on the page. Before I was using include but that screws up all the submit buttons. Anyone know of a simple code to embed a page? i wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers I have two messages in my PHP code, and one is displayed depending on whether or not an INSERT succeeds... // Verify Insert. if (mysqli_stmt_affected_rows($stmt)==1){ // Insert Succeeded. echo '<div id="box_Content_700b">'; echo '<h1>Member Account Created</h1>'; echo '<p>Congratulations!</p> <p>Your account has been created, and a confirmation e-mail sent to: "' . $email . '"</p> <p>Please click on the link in that e-mail to activate your account.</p>'; echo '</div>'; // Send Email. }else{ // Insert Failed. echo '<div id="box_Content_700b">'; echo '<h1>Account Creation Failed</h1>'; echo '<p>You could not be registered due to a system error.</p>'; echo '<p>Please contact the System Administrator.</p>'; echo '</div>'; }// End of VERIFY INSERT. Questions: 1.) Would it be better if I put those messages in MySQL and just queried the one I needed? 2.) If so, can I put the entire message and markup in the database, so everything is ready to display? 3.) Should I use VARCHAR() or TEXT()? Thanks, Debbie hello , i have this code: <?php function error_table($err){ echo"<p><span class='textborder'>$err</span></p>"; } ?> in a separate php file and then call it from another php file , like this : $msg_err='bla bla'; error_table($msg_err); when i click the button it shows the text with its border(the class has a border ,color and 1px) but when i have the code inside other if functions it shows it 2 or 3 times... i am having issues returning all sent messages. it will only return one for some reason. Code: [Select] //If there are sent messages, display them if ($row = mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result) or die(mysql_error()); //Open table and create headers echo "<table border=\"1\">\n"; echo " <tr>\n"; echo " <th>Recipient</th>\n"; echo " <th>Subject</th>\n"; echo " </tr>\n"; while(mysql_fetch_array($result)) { //Show messages $userIDTo = $row['userIDTo']; // Get the recipient's ID number $recipient = checkRecipient($userIDTo); // Get the sender's Username $messageID = $row['ID']; echo " <tr>\n"; echo " <td>{$recipient}</td>\n"; echo " <td><a href='messageDetails.php?messageID=$messageID' target='_blank'>{$row['subject']}</a></td>\n"; echo " <tr>\n"; } thanks in advance. I have to get the error messages to appear...but for some reason they're not showing up if I leave the forms blank and click submit. Code: [Select] <? $PROVINCES = array( "--" => "--- Please Select Provinces ---", "nf"=>"Newfoundland", "pe"=>"Prince Edward Island", "nb"=>"New Brunswick", "ns"=>"Nova Scotia", "qc"=>"Quebec", "on"=>"Ontario", "mb"=>"Manitoba", "sk"=>"Saskatchewan", "ab"=>"Alberta", "bc"=>"British Columbia", "nt"=>"Northwest Territories"); if ($_SERVER['REQUEST_METHOD'] == 'GET') { $dimwelcomeMsg = TRUE; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_POST['uname'] == ''){ $errMsg['uname'] = "Username must not be blank!!!"; $unameInError = true; } if (empty($_POST['year']) == TRUE){ $errMsg['year'] = "Year must not be blank!!"; } if (count($errMsg) > 0 ): $dispErrorMsg = TRUE; else: foreach ($_POST as $key => $val): $key = strtoupper($key); $successMsg[$key] = $val; endforeach; $dispSuccessMsg = TRUE; endif; } ?> <html > <head> <title>Comp10065 - Simple Form Validatioon</title> <style type="text/css"> body { margin: 0; padding: 0; font: 80%/1.5 Arial,Helvetica,sans-serif; color: #111; background-color: green; } h2 { margin: 0px; padding: 10px; font-family: Georgia, "Times New Roman", Times, serif; font-size: 200%; font-weight: normal; color: #FFF; background-color: #CCC; border-bottom: #BBB 2px solid; } h1 {color:#006600} p#copyright { margin: 20px 10px; font-size: 90%; color: #999; } div.form-container { margin: 10px; padding: 5px; background-color: #FFF; border: #EEE 1px solid; } p.legend { margin-bottom: 1em; } p.legend em { color: #C00; font-style: normal; } div.errors { margin: 0 0 10px 0; padding: 5px 10px; border: #FC6 1px solid; background-color: #FFC; } div.errors p { margin: 0; } div.errors p em { color: #C00; font-style: normal; font-weight: bold; } div.success { margin: 0 0 10px 0; padding: 5px 10px; border: #FC6 1px solid; background-color: #FFC; } div.success p { margin: 0; color:#006633} div.success li {list-style-type: none; } div.form-container form p { margin: 0; } div.form-container form p.note { margin-left: 170px; font-size: 90%; color: #333; } div.form-container form fieldset { margin: 10px 0; padding: 10px; border: #DDD 1px solid; } div.form-container form legend { font-weight: bold; color: #666; } div.form-container form fieldset div { padding: 0.25em 0; } div.form-container label, div.form-container span.label { margin-right: 10px; padding-right: 10px; width: 150px; display: block; float: left; text-align: right; position: relative; } div.form-container label.error, div.form-container span.error { color: #000; } div.form-container select.error, div.form-container div.error {background-color: #FEF;} div.form-container label em, div.form-container span.label em { position: absolute; right: 0; font-size: 120%; font-style: normal; color: #C00; } div.form-container input.error { border-color: #C00; background-color: #FEF; } div.form-container input:focus, div.form-container input.error:focus, div.form-container textarea:focus { background-color: #FFC; border-color: #FC6; } div.form-container div.controlset {margin: 3px} div.form-container div.controlset label, div.form-container div.controlset input { display: inline; float: none; } div.form-container div.controlset div { margin-left: 170px; } div.form-container div.buttonrow { padding-left: 430px; border: 1px solid #CCCCCC } div#wrapper {width: 700px ; margin-left: auto; margin-right: auto} pre {color:black; font-size: 10pt; font-weight: bold; margin-left: 30px} </style> </head> <body> <div id="wrapper"> <h1> Form Validation Lab</h1> <div class="form-container"> <? if ($_SERVER['REQUEST_METHOD'] == 'GET') : ?> <? if (displayWelcomeMsg) : ?> <p>Please fill in the form........</p> <? endif; ?> <? endif; ?> <? if ($displaySuccessMsg): ?> <div class="success"> <p>Thank you for your submission.</p> <ol> <? foreach($successMsgs as $key => $successMsg): ?> <li><?= $key ?> = <?= $successMsg ?> </li> <? endforeach; ?> </ol> </div> <? endif; ?> <? if ($dispErrorMsg) : ?> <div class="errors"> <p><em>Oops...the following errors were encountered</em></p> <ul> <? foreach ($errMsgs as $key => $errMsg): ?> <li><?= $errMsg ?> </li> <? endforeach; ?> </ul> <p>Please correct the errors and re-submit this form.</p> </div> <? endif; ?> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"> <input type="hidden" name="act" value="post"> <div class="buttonrow"> <input type="submit" value="Submit This Form " class="button" /> <a href="<?= $_SERVER['PHP_SELF'] ?>" >Start Again</a> </div> <p class="legend"><strong>Note:</strong> Required fields are marked with an asterisk (<em>*</em>)</p> <fieldset> <legend>User Details</legend> <div> <label for="uname" >User Name <em>*</em></label> <? if (isset($errMsgs['uname'])) echo 'class = "errors"' ?> <input id="uname" type="text" name="uname" value="<?=$_POST['uname'] ?>" /> (must be greater than 5 chars)</div> <div> <label for="email">Email Address </label> <input id="email" type="text" name="email" value="" /> </div> </fieldset> <fieldset> <legend>Submission</legend> <div> <label for="year">Year (YYYY) <em>*</em></label> <input id="year" type="text" name="year" <? if (isset($errMsgs['year'])) echo 'class = "errors"' ?> value="" size="4" maxlength="4" /> (4 digit number)</div> <div> <label for="date">Month (MM)</label> <input id="date" type="text" name="month" value="" size="4" maxlength="2" /> (number ranging from 1-12)</div> </fieldset> <fieldset> <legend>Preferences</legend> <div> <label for="type" >Province (Multiple Select) <em>*</em></label> <select name = "province[]" multiple size = "12" id="type" > <? foreach ($PROVINCES as $abbreviation => $longname); ?> <option value = "<?=$abbreviation ?> "></option> <? enfgoreach; ?> </select> </div> <div class= 'controlset' > <span class="label">Status (Mult Select)<em>*</em></span> <input name="status[]" id="approved" value="approved" type="checkbox" /> <label for="approved">Approved</label> <input name="status[]" id="pending" value="pending" type="checkbox" /> <label for="pending">Pending Application</label> <input name="status[]" id="actives" value="actives" type="checkbox" /> <label for="actives">Active Service</label> </div> <div class= 'controlset'> <span class="label"> Location <em>*</em></span> <input name="location" id="radio1" value="Garage" type="radio" /> <label for="radio1">Garage</label> <input name="location" id="radio2" value="Attic" type="radio" /> <label for="radio2">Attic</label> <input name="location" id="radio3" value="House" type="radio" /> <label for="radio3">House</label> </div> </fieldset> </form> <p>This debug info is here to help you. You are only required to display the POST array</p> <pre><?= print_r($_POST,true) ?> </pre> </div> </div> </body> </html> i am trying to retrieve messages with some code. It seems to be a bit more complicated that i thought it would be. so here it goes: Code: [Select] $query = "SELECT * FROM memberMail WHERE userIDFrom='92' AND unread='1'"; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result) or die(mysql_error()); $num_rows = mysql_num_rows($result); echo "You have (" . $num_rows . ") unread message(s)."; $i = 0; for($i; $i<$num_rows; ++$i) { if($row[$i[unread]] == "1") { echo $row[$i[message]] . "<p>"; } } } what i am trying to do, is print out the messages from the records that are unread, and are from a certain user. i don't think this for statement will pick up the record numbers that got matches though. and i am not entirely sure about the $row statements in the for statement either. Hello, I have a client with a "contact us" form who has recently been receiving a lot of spam emails from the form. I already have a session set in place so the form is only active one time. I am now creating a filter for the message to look for things like a url or bb style codes etc. What I've got seems to be working but would like your thoughts on maybe a better way of doing it or if you see something I may be missing. IF an offending text is detected the ip address is sent to me and I can block ip from the site. If the message passes it is sent to the client. This is the related code. Code: [Select] <?php $themessage=str_replace("\r",'<br>',$_POST['message']); $badwords=array("[", "url", "http", "link", ".com", ".net", ".org", ".biz", "<"); $o=0; foreach($badwords as $key2 => $value2){ $pos = strpos($themessage, $value2); if ($pos==0) { } else{ $o=$o+1; } } if ($o==0) { //compose and send email to client } else{ $useraddress=$_SERVER['REMOTE_ADDR']; //compose and send email to me containing offending address } ?> Guys, give me an idea of using a free or open sorce software for transferring messages over a local network between computers using MAC OS and Linux platforms.
Hi, I am creating a cms using php and my sql for my website. I have managed to create the majority of it but am having trouble added a menu on each page. It appears on the homepage with the following code: <ul id="headlines"> <?php foreach ( $results['articles'] as $article ) { ?> <li> <h2> <a href=".?action=viewArticle&articleId=<?php echo $article->id?>"><?php echo htmlspecialchars( $article->title )?></a> </h2> </li> <?php } ?> </ul> Once I click on a selection from the menu it takes me to the correct article but there is no menu now. If I try to copy and paste the code from homepage into my viewArticle file it gives me the error messages 'undefined index articles on line 6' and 'invalid argument supplied for for each'. This is the viewArticle code after I pasted in the code from homepage: <ul id="headlines"> <?php foreach ( $results['articles'] as $article ) { ?> <li> <h2> <a href=".?action=viewArticle&articleId=<?php echo $article->id?>"><?php echo htmlspecialchars( $article->title )?></a> </h2> </li> <?php } ?> </ul> <h1 style="width: 75%;"><?php echo htmlspecialchars( $results['article']->title )?></h1> <div style="width: 75%;"><?php echo $results['article']->content?></div> I would really appreciate anybody helping me figure out how I can add the menu onto the viewArticle page. Thanks in advance this is my first post (besides introduction and a comment in introduction) so im not 100% sure what all i am suppose to post for you guys so i will give it my best shot.. i have read 90% of rules though so i know what NOT to post lol here it goes: i am trying to get new messages to appear on header of my site but the alert (number) is not showing up.. this is in the <head> Code: [Select] <? include('inc.settings.php'); include('inc.networth.php'); @mysql_connect($dbhost, $dbuser, $dbpass); @mysql_select_db($dbname) or die("Error opening database"); $sqld = "SELECT * from og_userinfo where id=$userid"; $resultd = @mysql_query($sqld); $myrowd = @mysql_fetch_array($resultd); $networthck = $myrowd[networth]; $sqlornk = "SELECT count(*) from og_userinfo where networth > $networthck"; $resultornk = @mysql_query($sqlornk); $myrowornk = @mysql_fetch_array($resultornk); $orank = $myrowornk[0] + 1; $netstate = $myrowd[state]; $sqlornk2 = "SELECT count(*) from og_userinfo where networth > $networthck AND state=$netstate"; $resultornk2 = @mysql_query($sqlornk2); $myrowornk2 = @mysql_fetch_array($resultornk2); $orank2 = $myrowornk2[0] + 1; $pc_rank = $orank2 - 1; $pchk_rank = floor($pc_rank / 20); $plimit = $pchk_rank * 20; ?> --this is in the body-- Code: [Select] <table id="center" width="393" height="104" align="center" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="5"> <img src="images/center_01.gif" width="393" height="13" alt=""></td> </tr> <tr> <td rowspan="6"> <img src="images/center_02.gif" width="10" height="91" alt=""></td> <td width="372" height="28" colspan="3" align="center" bgcolor="#000000" alt="round time">round ends in: <? echo $dleft?> days, <? echo $hleft?> hours, <? echo $mleft?> minutes, <? echo $sleft?> seconds</td> <td rowspan="6"> <img src="images/center_04.gif" width="11" height="91" alt=""></td> </tr> <tr> <td colspan="3"> <img src="images/center_05.gif" width="372" height="8" alt=""></td> </tr> <tr> <td width="152" height="23" align="center" bgcolor="#000000" alt="messages"><a href="messages.php?uid=<? echo $uid ?>&secid=<? echo $secid ?>&type=1">messages</a> (<? echo $mmyrow[0] ; ?>)</td> <td rowspan="3"> <img src="images/center_07.gif" width="68" height="49" alt=""></td> <td width="152" height="23" align="center" bgcolor="#000000" alt="cartel messages"><a href="view.cartel.messages.php?uid=<? echo $uid ?>&secid=<? echo $secid ?>&type=1">cartel messages</a> (x)</td> </tr> <tr> <td> <img src="images/center_09.gif" width="152" height="4" alt=""></td> <td> <img src="images/center_10.gif" width="152" height="4" alt=""></td> </tr> <tr> <td width="152" height="22" align="center" bgcolor="#000000" alt="message board"><a href="cafe.messages.php?uid=<? echo $uid ?>&secid=<? echo $secid ?>&type=1">message board</a></td> <td width="152" height="22" align="center" bgcolor="#000000" alt="attacks"><a href="messages.php?uid=<? echo $uid ?>&secid=<? echo $secid ?>&type=2">attacks</a> (<? echo $mmyrow1[0] ; ?>)</td> </tr> <tr> <td colspan="3"> <img src="images/center_13.gif" width="372" height="6" alt=""></td> </tr> </table> i would really like the new messages to be in javascript so they show in real time instead of refreshing page but i know even less about that and all i can find info on on google is popup alerts which i dont want this is an image of the look im going for: |