PHP - Moved: Implementing Phpmailer
This topic has been moved to Other Libraries and Frameworks.
http://www.phpfreaks.com/forums/index.php?topic=358005.0 Similar TutorialsThis topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=359340.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=351506.0 hey guys im using phpmailer (https://github.com/PHPMailer/PHPMailer) to send mail from my server to users using SMTP...the problem im getting is that when i send a mail it goes stright into the junk mail...how can i please stop this please?
$mail = new \Mail\Mail; $mail->isSMTP(); $mail->Debugoutput = 'html'; $mail->Host = "****"; $mail->Port = 25; $mail->SMTPAuth = true; $mail->Username = "****"; $mail->Password = "***"; $mail->setFrom('***', '****'); $mail->addAddress('email@hotmail.co.uk', 'user'); $mail->Subject = 'BiSi - Welcome'; $mail->msgHTML('<a href="test">hello</a>'); $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; if (!$mail->send()) { echo "Mailer Error: "; } else { echo "Message sent!"; } Hi. I'm using PHP mailer. But I can't get it to send the Email: Class: Code: [Select] public function send_notification($sendTo, $name, $from_name, $from_email, $body_content, $subject){ $message =<<<EMAILBODY {$body_content} EMAILBODY; $message = wordwrap($message, 70); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "localhost"; $mail->Port = 25; $mail->SMTPAuth = false; $mail->isHTML(TRUE); $mail->FromName = $from_name; $mail->From = $from_email; $mail->AddAddress($sendTo, $name); $mail->Subject = $subject; $mail->Body = $message; $result = $mail->Send(); return $result; } PHP Code: [Select] $body_content = ' Dear BusinessMobile.com <br /><br /> A website user has filled in the form on the website. See the details below. <br /><br /> Company: '.$company.'<br /> Name: '.$name.'<br /> Email: '.$email.'<br /> Tele: '.$telephone.'<br /> Message: '.$message.'<br /><br /> Interest: '.$Fpage.'<br /> Reference: '.$ref.'<br /><br />'; $subject = 'BusinessMobile.com - Contact Request'; Form_signup::send_notification('spires1@mail.com', 'BM', 'BM', 'spires1@mail.com', $body_content, $subject); Any ideas where i'm going wrong ? Thanks Will someone, who doesn't mind helping an old man understand some things, explain how to use PHPMailer?
You see, I downloaded a registration form that sends a verification e-mail. I'm testing all of this on my local machine (Linux). The mail, of course, fails to be delivered. So I surf around and see where phpmailer can help me with this. So I downloaded phpmailer-master. But I have absoultely no idea where to put what so I'll have e-mail capability from localhost.
If you can tell me what goes where, I promise to name my next child after ya I just need some guidance on this one. It has me totally confused!
Landslyde
PS: Happy 2015 to all!
Edited by Landslyde, 30 December 2014 - 11:17 PM. Can someone help me please?.... I'm using this Code: [Select] <form name="form1" method="post" action="create-b.php" enctype="application/x-www-form-urlencoded" style="margin:0px"> <input name="name" value="Anonymous" type="text" MAXLENGTH="15" style="position:absolute;width:650px;left:67px;top:142px;z-index:4"> <input name="subject" value="(No subject)" MAXLENGTH="15" type="text" style="position:absolute;width:650px;left:67px;top:166px;z-index:5"> <textarea name="body" MAXLENGTH="255" type="text" style="position:absolute;left:67px;top:191px;width:650px;height:98px;z-index:6"></textarea> <div id="captcha" style="position:absolute; overflow:hidden; left:10px; top:296px; z-index:8"> <input name="submit" type="submit" value="Create thread" style="position:absolute;left:614px;top:291px;z-index:7"> <?php require_once('captc/recaptchalib.php'); $publickey = "**************************************"; echo recaptcha_get_html($publickey); ?> </form>On the HTML side and this require_once('captc/recaptchalib.php'); $privatekey = "************************"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("<font color='red'><font size='12'><strong><center>The verification code you entered appears to be incorrect!"); } else { CONTENT CONTENT CONTENT CONTENT CONTENT ETC But it always returns "The verification code you entered appears to be incorrect!" Any idea what I'm doing wrong?... So I want to implement the concept of "entitlements" on my website for articles, but am unsure of the most efficient way to code things. @Barand looked at and was okay with my table structure, but my question deal with PHP... Here is a basic ERD of the relevant tables... MEMBER >|-------||- MEMBERSHIP_PLAN -||-------|< MEMBESHIP_PLAN_VERSION -||-------|< ENTTLEMENT >0-------||- ARTICLE
Up until now, the user would click on an Article link, and my "article.php" script would grab the Category, Sub-Category and Article slug from the URL, and go look for the particular instance of the Article in MySQL. But now I want to control who can see what - that is only Members at a certain paid level can see "premium" content.
Here are my tables...
MEMBERSHIP_PLAN - id - name
MEMBERSHIP_PLAN_VERSION - id - plan_id - version_no - start_date - end_date
ENTITLEMENT - id - plan_id - version_id -article_id
ARTICLE - id - slug - title - body
And here is how I am thinking of approaching things, but would appreciate your thoughts...
- Member clicks on a link to the article: "How to use Indexes to Tune MySQL" - article.php loads and grabs the category/Sub-Category/Slug from the URL **new** - call getMembershipPlan( ) which grabs memberID from $_SESSION, queries MySQL , and returns "Membership Plan" - call getMembershipPlanVersion( ) which takes the Member's "Membership Plan", queries MySQL, and returns current/latest version - call getArticleEntitlement( ) which takes "Membership Plan", "Membership Plan Version" and "Article Slug", queries MySQL, and returns TRUE if this member is "entitled" to view the chosen Article **end of new** - Take "Category", "Sub-Category' and "Article Slug", query MySQL, and return Article and related metadata - Populate Article on page, OR display error: "This article is only available to Premium Members..."
What do you think about this approach?
Is it a sin to have 3 PHP functions and make 3 calls to MySQL? (This relates to my last thread asking about how much to store in my SESSION variable.
Edited February 18, 2020 by SaranacLake I am trying to write a PHP script that implements the MD5 algorithm just so that I can better understand MD5's inner-workings. For those of you already familiar with how MD5 works, could you help me figure out why my script is not producing the correct output? <?php $string = ""; $a = "01100111010001010010001100000001"; // 0x67452301 $b = "11101111110011011010101110001001"; // 0xEFCDAB89 $c = "10011000101110101101110011111110"; // 0x98BADCFE $d = "00010000001100100101010001110110"; // 0x10325476 $aa = $a; $bb = $b; $cc = $c; $dd = $d; // PADDED BINARY FOR NULL STRING, I.E.: "" $binary_md5 = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; $binary_md5_words = strlen($binary_md5) / 32; // SPLIT BINARY INTO 16 32-BIT WORDS for($i = 1; $i <= $binary_md5_words; $i++) { $m[] = substr($binary_md5, ($i - 1) * 32, 32); } // GENERATE T-VALUES for($i = 0; $i < 64; $i++) { $T[] = Pad(decbin(floor(4294967296 * abs(sin($i+1)))), 32); } /* // PRINT THE M[K] ARRAY echo "<h1>m[k] Array</h1><br>"; print_r($m); echo "<br><br>"; // PRINT THE T[t] ARRAY echo "<h1>T[t] Array</h1><br>"; print_r($T); echo "<br><br>"; // TEST ANDxy echo "<h1>Test ANDxy</h1><br>"; echo "$m[0]<br>$T[0]<br>"; echo ANDxy($m[0], $T[0]); echo "<br><br>"; // TEST ORxy echo "<h1>Test ORxy</h1><br>"; echo "$m[0]<br>$T[0]<br>"; echo ORxy($m[0], $T[0]); echo "<br><br>"; // TEST ADDxy echo "<h1>Test ADDxy</h1><br>"; echo "$m[0]<br>$T[0]<br>"; echo ADDxy($m[0], $T[0]); echo "<br><br>"; // TEST XORxy echo "<h1>Test XORxy</h1><br>"; echo "$m[0]<br>$T[0]<br>"; echo XORxy($m[0], $T[0]); echo "<br><br>"; // TEST NOTx echo "<h1>Test NOTx</h1><br>"; echo "$m[0]<br>"; echo NOTx($m[0]); echo "<br><br>"; // TEST SHIFTleft echo "<h1>Test SHIFTleft</h1><br>"; echo "$m[0]<br>"; echo SHIFTleft($m[0], 1); echo "<br><br>"; // TEST F echo "<h1>Test F</h1><br>"; echo "X = $m[0]<br>Y = $m[1]<br>Z = $m[2]<br>F = "; echo F($m[0], $m[1], $m[2]); $step1 = ANDxy($m[0], $m[1]); $step2 = ANDxy(NOTx($m[0]), $m[2]); $step3 = ORxy($step1, $step2); echo "<br>F = $step3"; echo "<br><br>"; // TEST H echo "<h1>Test H</h1><br>"; echo "X = $m[0]<br>Y = $m[1]<br>Z = $m[2]<br>F = "; echo H($m[0], $m[1], $m[2]); echo "<br><br>"; */ // ROUND 1 $a = ff($a, $b, $c, $d, $m, 0, 7, $T[0]); $d = ff($d, $a, $b, $c, $m, 1, 12, $T[1]); $c = ff($c, $d, $a, $b, $m, 2, 17, $T[2]); $b = ff($b, $c, $d, $a, $m, 3, 22, $T[3]); $a = ff($a, $b, $c, $d, $m, 4, 7, $T[4]); $d = ff($d, $a, $b, $c, $m, 5, 12, $T[5]); $c = ff($c, $d, $a, $b, $m, 6, 17, $T[6]); $b = ff($b, $c, $d, $a, $m, 7, 22, $T[7]); $a = ff($a, $b, $c, $d, $m, 8, 7, $T[8]); $d = ff($d, $a, $b, $c, $m, 9, 12, $T[9]); $c = ff($c, $d, $a, $b, $m, 10, 17, $T[10]); $b = ff($b, $c, $d, $a, $m, 11, 22, $T[11]); $a = ff($a, $b, $c, $d, $m, 12, 17, $T[12]); $d = ff($d, $a, $b, $c, $m, 13, 12, $T[13]); $c = ff($c, $d, $a, $b, $m, 14, 17, $T[14]); $b = ff($b, $c, $d, $a, $m, 15, 22, $T[15]); // ROUND 2 $a = gg($a, $b, $c, $d, $m, 1, 5, $T[16]); $d = gg($d, $a, $b, $c, $m, 6, 9, $T[17]); $c = gg($c, $d, $a, $b, $m, 11, 14, $T[18]); $b = gg($b, $c, $d, $a, $m, 0, 20, $T[19]); $a = gg($a, $b, $c, $d, $m, 5, 5, $T[20]); $d = gg($d, $a, $b, $c, $m, 10, 9, $T[21]); $c = gg($c, $d, $a, $b, $m, 15, 14, $T[22]); $b = gg($b, $c, $d, $a, $m, 4, 20, $T[23]); $a = gg($a, $b, $c, $d, $m, 9, 5, $T[24]); $d = gg($d, $a, $b, $c, $m, 14, 9, $T[25]); $c = gg($c, $d, $a, $b, $m, 3, 14, $T[26]); $b = gg($b, $c, $d, $a, $m, 8, 20, $T[27]); $a = gg($a, $b, $c, $d, $m, 13, 5, $T[28]); $d = gg($d, $a, $b, $c, $m, 2, 9, $T[29]); $c = gg($c, $d, $a, $b, $m, 7, 14, $T[30]); $b = gg($b, $c, $d, $a, $m, 12, 20, $T[31]); // ROUND 3 $a = hh($a, $b, $c, $d, $m, 5, 4, $T[32]); $d = hh($d, $a, $b, $c, $m, 8, 11, $T[33]); $c = hh($c, $d, $a, $b, $m, 11, 16, $T[34]); $b = hh($b, $c, $d, $a, $m, 14, 23, $T[35]); $a = hh($a, $b, $c, $d, $m, 1, 4, $T[36]); $d = hh($d, $a, $b, $c, $m, 4, 11, $T[37]); $c = hh($c, $d, $a, $b, $m, 7, 16, $T[38]); $b = hh($b, $c, $d, $a, $m, 10, 23, $T[39]); $a = hh($a, $b, $c, $d, $m, 13, 4, $T[40]); $d = hh($d, $a, $b, $c, $m, 0, 11, $T[41]); $c = hh($c, $d, $a, $b, $m, 3, 16, $T[42]); $b = hh($b, $c, $d, $a, $m, 6, 23, $T[43]); $a = hh($a, $b, $c, $d, $m, 9, 4, $T[44]); $d = hh($d, $a, $b, $c, $m, 12, 11, $T[45]); $c = hh($c, $d, $a, $b, $m, 15, 16, $T[46]); $b = hh($b, $c, $d, $a, $m, 2, 23, $T[47]); // ROUND 4 $a = ii($a, $b, $c, $d, $m, 0, 6, $T[48]); $d = ii($d, $a, $b, $c, $m, 7, 10, $T[49]); $c = ii($c, $d, $a, $b, $m, 14, 15, $T[50]); $b = ii($b, $c, $d, $a, $m, 5, 21, $T[51]); $a = ii($a, $b, $c, $d, $m, 12, 6, $T[52]); $d = ii($d, $a, $b, $c, $m, 3, 10, $T[53]); $c = ii($c, $d, $a, $b, $m, 10, 15, $T[54]); $b = ii($b, $c, $d, $a, $m, 1, 21, $T[55]); $a = ii($a, $b, $c, $d, $m, 8, 6, $T[56]); $d = ii($d, $a, $b, $c, $m, 15, 10, $T[57]); $c = ii($c, $d, $a, $b, $m, 6, 15, $T[58]); $b = ii($b, $c, $d, $a, $m, 13, 21, $T[59]); $a = ii($a, $b, $c, $d, $m, 4, 6, $T[60]); $d = ii($d, $a, $b, $c, $m, 11, 10, $T[61]); $c = ii($c, $d, $a, $b, $m, 2, 15, $T[62]); $b = ii($b, $c, $d, $a, $m, 9, 21, $T[63]); $a = ADDxy($a, $aa); $b = ADDxy($b, $bb); $c = ADDxy($c, $cc); $d = ADDxy($d, $dd); // ECHO RESULTS echo "<h1>String</h1><br>"; echo "String: '$string'<br>"; $md5 = md5($string); echo "MD5: $md5<br><br>"; $md5_1 = substr($md5, 0, 8); $md5_2 = substr($md5, 8, 8); $md5_3 = substr($md5, 16, 8); $md5_4 = substr($md5, 24, 8); echo "A = $md5_1<br>B = $md5_2<br>C = $md5_3<br>D = $md5_4<br><br>"; $md5_bin_a = Pad(decbin(hexdec($md5_1)), 32); $md5_bin_b = Pad(decbin(hexdec($md5_2)), 32); $md5_bin_c = Pad(decbin(hexdec($md5_3)), 32); $md5_bin_d = Pad(decbin(hexdec($md5_4)), 32); echo "A = $md5_bin_a<br>B = $md5_bin_b<br>C = $md5_bin_c<br>D = $md5_bin_d<br><br>"; echo "<h1>Results</h1><br>"; echo "A = $a<br>B = $b<br>C = $c<br>D = $d<br><br>"; $a_dec = bindec($a); $b_dec = bindec($b); $c_dec = bindec($c); $d_dec = bindec($d); $a_hex = dechex($a_dec); $b_hex = dechex($b_dec); $c_hex = dechex($c_dec); $d_hex = dechex($d_dec); echo "A = $a_hex<br>B = $b_hex<br>C = $c_hex<br>D = $d_hex<br><br>"; // FUNCTIONS function ff($a, $b, $c, $d, $m, $k, $s, $t) { //a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s) return ADDxy($b, SHIFTleft(ADDxy(ADDxy(ADDxy($a, F($b, $c, $d)), $m[$k]), $t), $s)); } function gg($a, $b, $c, $d, $m, $k, $s, $t) { //a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s) return ADDxy($b, SHIFTleft(ADDxy(ADDxy(ADDxy($a, G($b, $c, $d)), $m[$k]), $t), $s)); } function hh($a, $b, $c, $d, $m, $k, $s, $t) { //a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s) return ADDxy($b, SHIFTleft(ADDxy(ADDxy(ADDxy($a, H($b, $c, $d)), $m[$k]), $t), $s)); } function ii($a, $b, $c, $d, $m, $k, $s, $t) { //a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s) return ADDxy($b, SHIFTleft(ADDxy(ADDxy(ADDxy($a, I($b, $c, $d)), $m[$k]), $t), $s)); } function F($X, $Y, $Z) { //return ($X & $Y) | ((~$X) & $Z); return ORxy(ANDxy($X, $Y), ANDxy(NOTx($X), $Z)); } function G($X, $Y, $Z) { //return ($X & $Z) | ($Y & (~$Z)); return ORxy(ANDxy($X, $Z), ANDxy($Y, NOTx($Z))); } function H($X, $Y, $Z) { //return $X ^ $Y ^ $Z; return XORxy(XORxy($X, $Y), $Z); } function I($X, $Y, $Z) { //return $Y ^ ($X | (~$Z)); return XORxy($Y, ORxy($X, NOTx($Z))); } function Pad($binary, $pad_length) { $pad_length = $pad_length - strlen($binary); for($i = 0; $i < $pad_length; $i++) { $padding .= '0'; } return $padding . $binary; } function mod($val, $div) { $r = $val - (floor($val/$div)*$div); return $r; } function ANDxy($x, $y) { $x_dec = bindec($x); $y_dec = bindec($y); $result = $x_dec & $y_dec; $result = Pad(decbin($result), strlen($x)); return $result; } function ORxy($x, $y) { $x_dec = bindec($x); $y_dec = bindec($y); $result = $x_dec | $y_dec; $result = Pad(decbin($result), strlen($x)); return $result; } function ADDxy($x, $y) { $x_dec = bindec($x); $y_dec = bindec($y); $result = mod($x_dec + $y_dec, pow(2, 32)); $result = Pad(decbin($result), strlen($x)); return $result; } function XORxy($x, $y) { $x_dec = bindec($x); $y_dec = bindec($y); $result = $x_dec ^ $y_dec; $result = Pad(decbin($result), strlen($x)); return $result; } function NOTx($x) { $x_dec = bindec($x); $result = ~$x_dec; $result = Pad(decbin($result), strlen($x)); return $result; } function SHIFTleft($x, $y) { $x_dec = bindec($x); $result = $x_dec << $y; $result = Pad(decbin($result), strlen($x)); return $result; } function SHIFTright($x, $y) { $x_dec = bindec($x); $result = $x_dec >> $y; $result = Pad(decbin($result), strlen($x)); return $result; } ?> I have been away from a coding project for over 2 years. Trying to get things online, and not cause further delays. My site uses the PHP Mailer class to send out emails to users for things like password resets. How important is it that I have the latest version of this class - assuming it is even still around now? Thanks. I downloaded the PHPMailer. I can send email from gmail mail server to the registered users in my website smoothly. But when I upload it to my web host basically I edited all the credentials and apply my new host mail server username, password, host, port, etc. When i try to send this is the error: Code: [Select] SMTP Error: Authentication Failed and this is my code Code: [Select] <?php session_start(); ?> <html> <head> <title>PHPMailer - SMTP (Gmail) basic test</title> </head> <body> <form action="GET"> <?php $pEmail = $_SESSION['uEmail']; $pUser = $_SESSION['user']; $eTitle = $_SESSION['uTitle']; $eDesc = $_SESSION['uDesc']; $ePrice = $_SESSION['uPrice']; //error_reporting(E_ALL); error_reporting(E_STRICT); //date_default_timezone_set('America/Toronto'); require_once('class.phpmailer.php'); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); //$body = file_get_contents('contents.php'); //$body = eregi_replace("[\]",'',$body); $body = "Welcome to GankGames, ".$pUser. "<br><br> Your Game has been uploaded successfully!<br><br> Below is the summary of your upload transaction: <br><br> Game Name: ".$eTitle."<br> Game Description: ".$eDesc."<br> Game Price: ".$ePrice."<br><br> Your game will be verified in 24 hours for security purposes. After verifying we will going to send you again an email informing you that your game is already active <br><br><br> Thank you very much!!"; $mail->IsSMTP(); // telling the class to use SMTP $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "ssl"; // sets the prefix to the servier $mail->Host = "mail.********.com"; // sets GMAIL as the SMTP server $mail->Port = 465; // set the SMTP port for the GMAIL server $mail->Username = "gankgames@almarioit115p.com"; // GMAIL username $mail->Password = "*********"; // GMAIL password $mail->SetFrom('mail.********.com', 'admin@gankgames.com'); //$mail->AddReplyTo("teitoklein01@gmail.com","jm"); $mail->Subject = "Game Verification"; //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $address = $pEmail; $mail->AddAddress($address, $pUser); //$mail->AddAttachment("images/phpmailer.gif"); // attachment //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { //echo "Message sent!"; //$_SESSION['uploaded'] = "Uploaded Successfully"; $upload = "Uploaded Successfully"; ob_start(); header("Location: confirm.php?pupload=$upload"); ob_end_flush(); } ?> </form> </body> </html> help I am working on a webform that sends an email when submitted. The following output appears intermittently on the form.php page (I have currently disabled the page forwarding so I can see the output more easily). I am not quite sure what is going on, but when this occurs, no email is sent. Here's what the output looks like: Code: [Select] SMTP -> FROM SERVER: SMTP -> FROM SERVER: SMTP -> ERROR: HELO not accepted from server: SMTP -> FROM SERVER: SMTP -> ERROR: MAIL not accepted from server: Message could not be sent. Mailer Error: SMTP Error: From address [myemail@myserver.com] failed This same file and same configuration has worked on and off, even when no changes are made. It seems that maybe the server is simply denying connections for some reason, but I'm not entirely sure, hence the post here. Any suggestions or ideas for debugging are GREATLY appreciated. Thanks! I am setting up PHPMailer to send pdf's from my server and I have just come into the following error: Quote Deprecated: Function set_magic_quotes_runtime() is deprecated in /var/www/PHPMailer_v5.1/class.phpmailer.php on line 1471 Deprecated: Function set_magic_quotes_runtime() is deprecated in /var/www/PHPMailer_v5.1/class.phpmailer.php on line 1475 The code in question is this (I've pointed out the lines mentioned above): Code: (php) [Select] <?php /** * Encodes attachment in requested format. * Returns an empty string on failure. * @param string $path The full path to the file * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' * @see EncodeFile() * @access private * @return string */ private function EncodeFile($path, $encoding = 'base64') { try { if (!is_readable($path)) { throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); } if (function_exists('get_magic_quotes')) { function get_magic_quotes() { return false; } } if (PHP_VERSION < 6) { $magic_quotes = get_magic_quotes_runtime(); set_magic_quotes_runtime(0); //<-- Here } $file_buffer = file_get_contents($path); $file_buffer = $this->EncodeString($file_buffer, $encoding); if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); } //<-- Here return $file_buffer; } catch (Exception $e) { $this->SetError($e->getMessage()); return ''; } } So my question is, how can I get rid of this error? How should I best edit this function to no longer use the deprecated set_magic_quotes_runtime()? Any help is appreciated, Joe
I am new to phpmailer and still trying to learn and understand it, I can do the basics in it if want to just use it to send a email but now want to use it to send attachments but the attachments are optional and only want to be able to send jpg and png attachments but am trying to concentrate on one thing at a time but getting frustrated with it. I am currently trying to get it so that the attachments are not required so if the user sends the form with no attachments, the form sends all ok and the same as if the user sends attachments, below is my current code but is not working, am getting unexpected errors as either ; or } $attachmentNames = []; //Attach multiple files one by one for ($ct = 0; $ct < count($_FILES['userfile']['tmp_name']); $ct++) { $uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct])); $filename = $_FILES['userfile']['name'][$ct]; if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) { $mail->addAttachment($uploadfile, $filename); $attachmentNames[] = $_FILES['userfile']['name'][$ct]; } else { $msg .= 'Failed to move file to ' . $uploadfile; } if ($mail->addAttachment { $msg .= 'Failed to attach file' } } $mail->Subject = 'New Repair Booking Made At' . ' ' .date('d-m-Y H:i:s'); $mail->Body = "A new repair has been booked in. This repair booking was made at " . $date = date('d-m-Y H:i:s') . "\r\n\r\n" . "The repair information is below" . "\r\n\r\n" . "Repair Date/Time: " . $_POST["date"] . "\r\n" . "Device: " . $_POST["selectdevice"] . "\r\n" . "Brand: " . $_POST["selectbrand"] . "\r\n" . "Name: " . $_POST["name"] . "\r\n" . "Email: " . $_POST["email"] . "\r\n" . "Phone Number: " . $_POST["phone"] . "\r\n" . "Repair Description/Issue: " . $_POST["repairdescription"] . "\r\n\r\n" . "Attached Filename(s): " . implode(', ', $attachmentNames);
I am trying to get phpmailer working but not having much luck with it. I am not receiving the email Below is the code I have <?php //index.php $error = ''; $quantity1 = ''; $totalprice1 = ''; $subtotal = ''; $postage = ''; $grandtotal = ''; $name = ''; $addressline1 = ''; $postcode = ''; $email = ''; function clean_text($string) { $string = trim($string); $string = stripslashes($string); $string = htmlspecialchars($string); return $string; } if(isset($_POST["submit"])) { if(empty($_POST["quantity1"])) { $error .= '<p><label class="text-danger">Please enter the quantity required</label></p>'; } if(empty($_POST["totalprice1"])) { $error .= '<p><label class="text-danger">Please enter the total price required</label></p>'; } if(empty($_POST["subtotal"])) { $error .= '<p><label class="text-danger">Please enter the subtotal</label></p>'; } if(empty($_POST["postage"])) { $error .= '<p><label class="text-danger">Please enter the postage</label></p>'; } if(empty($_POST["grandtotal"])) { $error .= '<p><label class="text-danger">Please enter the grand total</label></p>'; } if(empty($_POST["name"])) { $error .= '<p><label class="text-danger">Please Enter your name</label></p>'; } else { $name = clean_text($_POST["name"]); if(!preg_match("/^[a-zA-Z ]*$/",$name)) { $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>'; } } if(empty($_POST["addressline1"])) { $error .= '<p><label class="text-danger">Please enter your address line 1</label></p>'; } if(empty($_POST["postcode"])) { $error .= '<p><label class="text-danger">Please enter your postcode</label></p>'; } if(empty($_POST["email"])) { $error .= '<p><label class="text-danger">Please Enter your Email</label></p>'; } else { $email = clean_text($_POST["email"]); if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error .= '<p><label class="text-danger">Invalid email format</label></p>'; } } if($error == '') { require 'phpmailer/class.phpmailer.php'; $mail = new PHPMailer(true); $mail->SMTPDebug = 1; // to see exactly what's the issue $mail->IsSMTP(); //Sets Mailer to send message using SMTP $mail->Host = 'hostname'; //Sets the SMTP hosts $mail->Port = '587'; //Sets the default SMTP server port $mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables $mail->Username = 'emailaddress'; //Sets SMTP username $mail->Password = 'emailaddresspassword'; //Sets SMTP password $mail->SMTPSecure = ''; //Sets connection prefix. Options are "", "ssl" or "tls" $mail->From = $_POST["email"]; //Sets the From email address for the message $mail->FromName = $_POST["name"]; //Sets the From name of the message $mail->AddAddress('emailaddress', 'Name');//Adds a "To" address $mail->AddCC($_POST["email"], $_POST["name"]); //Adds a "Cc" address $mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters $mail->IsHTML(true); //Sets message type to HTML $mail->Subject = "Online Badge Order"; //Sets the Subject of the message $mail->Body = "The order information is below" . "<br><br>" . "Club One: " . $_POST["club1"] . "<br>" . "Country One: " . $_POST["country1"] . "<br>" . "Ref No: " . $_POST["refno1"] . "<br>" . "Quantity: " . "<br>" . $_POST["quantity1"] . "<br>" . "Total Price Line: " . "\243" . $_POST["totalprice1"] . "<br><br>" . "Club Two: " . $_POST["club2"] . "<br>" . "Country Two: " . $_POST["country2"] . "<br>" . "Ref No: " . $_POST["refno2"] . "<br>" . "Quantity: " . $_POST["quantity2"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice2"] . "<br><br>" . "Club Three: " . $_POST["club3"] . "<br>" . "Country Three: " . $_POST["country3"] . "<br>" . "Ref No: " . $_POST["refno3"] . "<br>" . "Quantity: " . $_POST["quantity3"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice3"] . "<br><br>" . "Club Four: " . $_POST["club4"] . "<br>" . "Country Four: " . $_POST["country4"] . "<br>" . "Ref No: " . $_POST["refno4"] . "<br>" . "Quantity: " . $_POST["quantity4"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice4"] . "<br><br>" . "Club Five: " . $_POST["club5"] . "<br>" . "Country Five: " . $_POST["country5"] . "<br>" . "Ref No: " . $_POST["refno5"] . "<br>" . "Quantity: " . $_POST["quantity5"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice5"] . "<br><br>" . "Club Six: " . $_POST["club6"] . "<br>" . "Country Six: " . $_POST["country6"] . "<br>" . "Ref No: " . $_POST["refno6"] . "<br>" . "Quantity: " . $_POST["quantity6"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice6"] . "<br><br>" . "Club Seven: " . $_POST["club7"] . "<br>" . "Country Seven: " . $_POST["country7"] . "<br>" . "Ref No: " . $_POST["refno7"] . "<br>" . "Quantity: " . $_POST["quantity7"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice7"] . "<br><br>" . "Club Eight: " . $_POST["club8"] . "<br>" . "Country Eight: " . $_POST["country8"] . "<br>" . "Ref No: " . $_POST["refno8"] . "<br>" . "Quantity: " . $_POST["quantity8"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice8"] . "<br><br>" . "Club Nine: " . $_POST["club9"] . "<br>" . "Country Nine: " . $_POST["country9"] . "<br>" . "Ref No: " . $_POST["refno9"] . "<br>" . "Quantity: " . $_POST["quantity9"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice9"] . "<br><br>" . "Club Ten: " . $_POST["club10"] . "<br>" . "Country Ten: " . $_POST["country10"] . "<br>" . "Ref No: " . $_POST["refno10"] . "<br>" . "Quantity: " . $_POST["quantity10"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice10"]; //An HTML or plain text message body if($mail->Send()) //Send an Email. Return true on success or false on error { header('Location:thank-you.html'); } else { $error = '<label class="text-danger">There is an Error</label>'; } $quantity1 = ''; $totalprice1 = ''; $subtotal = ''; $postage = ''; $grandtotal = ''; $name = ''; $addressline1 = ''; $postcode = ''; $email = ''; } } ?>
Hello, I am a PHP beginner and I made a PHP page which inserts data into a MYSql database. .... $InsertQuery->Action = "insert"; $InsertQuery->Table = "klanten"; $InsertQuery->bindColumn("Klantnummer", "s", "".strtoupper(((isset($_POST["Klantnummer"]))?$_POST["Klantnummer"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("Naam_organisatie", "s", "".strtoupper(((isset($_POST["Naam_organisatie"]))?$_POST["Naam_organisatie"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("Adres_organisatie", "s", "".strtoupper(((isset($_POST["Adres_organisatie"]))?$_POST["Adres_organisatie"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("Postcode_organisatie", "s", "".strtoupper(((isset($_POST["Postcode_organisatie"]))?$_POST["Postcode_organisatie"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("Woonplaats_organisatie", "s", "".strtoupper(((isset($_POST["Woonplaats_organisatie"]))?$_POST["Woonplaats_organisatie"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("BTW_plichtig", "s", "".strtoupper(((isset($_POST["BTW_plichtig"]))?$_POST["BTW_plichtig"]:"")) ."", "WA_DEFAULT"); $InsertQuery->bindColumn("Email", "s", "".strtoupper(((isset($_POST["Email"]))?$_POST["Email"]:"")) ."", "WA_DEFAULT"); ... After the insert, I want to send all the data with a mail to a recepient. But I can't find a way to code the "setForm" correctly with the inserted field "Email". <?php error_reporting(E_ALL); use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\src\Exception; require 'PHPMailer\PHPMailer\src\Exception.php'; require 'PHPMailer\PHPMailer\src\PHPMailer.php'; require 'PHPMailer\PHPMailer\src\SMTP.php'; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "smtp.myhosting.be"; $mail->SMTPAuth = true; $mail->Username = 'username@domain.com'; $mail->Password = 'password'; $mail->setFrom = $_POST('Email'); // doesn't work $mail->AddAddress('recipient@domain.com'); $mail->Subject = "subject"; $mail->Body = "text"; // in the body I want an overview of all the inserted data $mail->IsHTML(true); if(!$mail->Send()) { echo "Error sending: " . $mail->ErrorInfo;; } $mail->ClearAddresses(); $mail->ClearAttachments(); ?>
How can I do that? Hey sup guys i need help Implementing top 10 users script into index.php. I got a screen shot of where it needs to go. I need to Implement it so its inside the grey container as in the picture. Here is the php for the top 10 users : Code: [Select] <span style="float:right;"> <table width="200"> <tr><td colspan="2" align="center">TOP 10 USERS</td></tr> <tr><td align="left"><b>Username<b></td><td align="left"><b>Points</b></td></tr> <?php $i=0; if($num>0){ while ($i < $num) { $username6=mysql_result($result4,$i,"username"); $points6=mysql_result($result4,$i,"points"); $i++; echo "<tr><td>".$username6."</td><td>".$points6."</td></tr>"; Here is the image file for the graphic : Code: [Select] <table width="165" height="236" bgcolor="#FFFFFF" td background="images/tablebg.png" > And here is the index.php : Code: [Select] <? session_start(); include_once"config.php"; if(isset($_POST['login'])){ $username= trim($_POST['username']); $password = trim($_POST['password']); if($username == NULL OR $password == NULL){ $final_report.="Please complete both fields"; }else{ $check_user_data = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error()); if(mysql_num_rows($check_user_data) == 0){ $final_report.="This username does not exist"; }else{ $get_user_data = mysql_fetch_array($check_user_data); if($get_user_data['password'] == $password){ $start_idsess = $_SESSION['username'] = "".$get_user_data['username'].""; $start_passsess = $_SESSION['password'] = "".$get_user_data['password'].""; $final_report.="<meta http-equiv='Refresh' content='0; URL=members.php'/>"; }}}} if(isset($_SESSION['username']) && isset($_SESSION['password'])){ header("Location: members.php"); } ?> <?php include("includes.php");?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo $title ?> | #1 Spot for Free Paid Surveys</title> <link rel="shortcut icon" href="favicon.ico" > <link rel="icon" type="image/gif" href="animated_favicon1.gif" > <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="description" content="Get free vouchers for online stores such as Amazon, ASOS, iTunes and more. It takes a few seconds to get started. Register now to start shopping for free." /> <link rel="stylesheet" href="style.css" type="text/css" /> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="js/script.js"></script> <script type="text/javascript" src="js/dimensions.min.js"></script> <script type="text/javascript" src="js/func.js"></script> <script type="text/javascript" src="js/SHA1.js"></script> <script>var _wau = _wau || []; _wau.push(["tab", "72vlo7dmnb8j", "w12", "bottom-center"]);(function() { var s=document.createElement("script"); s.async=true; document.getElementsByTagName("head")[0].appendChild(s);})();</script> <style> #logoPart { background:#000; height:90px;} #bannerTD { width:900px; height:85px; background-color:#333; background-repeat: no-repeat;} #bannerTD #bannerContainer { width:900px; height:325px; text-align:center;} #bannerTD #bannerContainerCover { width:900px; height:325px; text-align:center;} #bannerTD #bannerBody { height:245px; text-align:center;} #bannerTD #bannerFooter { position: relative; background:#000; height:80px; display:none; width:900px; top: -39px; /* 1x the distance of the footer used to be 78 */ } #bannerTD #bannerFooterNav { position: relative; border: 1px solid grey; top: -117px; /* 2x the distance of the footer used to be 156*/ } .footerCell{ padding:5px; text-align:left; border:0px #F90 solid;} .footerCell .footerTitle {font-family:tahoma, arial; font-size:11px; color:#fff; font-weight: bold;} .footerCell .footerDesc {font-family:tahoma, arial; font-size:11px; color:#efefef;} .footerCell ul {list-style: none; margin: 2px; margin-left: 75px; padding-left: 10px;} .footerCell ul li {margin: 2px; line-height: 13px; padding: 0;} .footerLink {text-align: right;} .footerCell .imgDiv{ position:relative; float:left; width:80px; height:65px; margin: 2px 1px 0px 1px;} .bttnMore {width:57px; height:19px; float: right;} .bttnMore a{display: block; background:url(images/welcome-banner/gen/bttn_more_small.png) 0 0 no-repeat; line-height: 19px; text-decoration: none;} .imgBgDiv_i { width:82px; height:67px; //background: url(images/welcome-banner/gen/thumbBgBordered.png) 0 0 no-repeat; padding: 0; float:left; } </style> </head> <body> <body id="exterior"> <div id="body-bg"> </div> <div id="container"> <div id="header"> <a href="index.php<?php echo $referral_string?>"> <div id="logo"> </div></a><!--end of logo--> <div id="updates"> <span> </span> </div><!--end of updates--> <div id="login"> <div id="loginwelcome"> <?php if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){ ?> <?php if($final_report !=""){?> <font color="red"><? echo $final_report;?></font> <?php }else { ?>Welcome Guest, not a member? <a href="register.php<?php echo $referral_string?>"><b>Register Now!</b></a> <?php } ?> </div><!--end of loginwelcome--> <form action="" method="post"> <p> <input type="text" title="username" name="username" class="username" value="Username" onclick="if ( value == 'Username' ) { value = ''; }"/> <input name="password" type="password" class="password" title="password" value="Password" onclick="if ( value == 'Password' ) { value = ''; }"/> <input type="Submit" name="login" class="submit" value="login" tabindex="3" /> </p> </form> </div><!--end of login--> <?php } ?> <?php if(isset($_SESSION['username']) && isset($_SESSION['password'])){ ?> <table> <tr> <td> Welcome <b><?php echo $membername ?></b> </td> </tr> <tr> <td align="right" width="310"> Total Points: <b><?php echo $memberpoints ?></b><br> <?php if ($pointsneeded<=0){ ?> You can now request a reward!<?php }else { ?> Points Needed: <b><?php echo $pointsneeded ?> <?php } ?> </b><br> </td> </tr> </table> </div> <!--end of header--> <?php } ?> <div id="navigation"> <?php if(isset($_SESSION['username']) && isset($_SESSION['password'])){ ?> <table id="navi-items"> <tr><td> <div class="navi-item navi-item-selected"> <div class="navi-heading navi-heading-selected"> <a href="index.php"><img src="images/home.png" alt="Home" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="vouchers.php"><img src="images/rewards.png" alt="Rewards" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="testimonials.php"><img src="images/testimonials.png" alt="Testimonials" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="terms.php"><img src="images/terms.png" alt="Terms" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="help.php"><img src="images/help.png" alt="Help" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="contact.php"><img src="images/contact-us.png" alt="Contact Us" /></a> </div> </div> </td></tr> </table> <?php }else { ?> <table id="navi-items"> <tr><td> <div class="navi-item navi-item-selected"> <div class="navi-heading navi-heading-selected"> <a href="index.php"><img src="images/home.png" alt="Home" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="vouchers.php"><img src="images/rewards.png" alt="Rewards" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="testimonials.php"><img src="images/testimonials.png" alt="Testimonials" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="terms.php"><img src="images/terms.png" alt="Terms" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="help.php"><img src="images/help.png" alt="Help" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="contact.php"><img src="images/contact-us.png" alt="Contact Us" /></a> </div> </div> </td></tr> </table> <?php } ?> </div><!--end of navigation--> <!-- ______________________ BANNER ___________________--> <tr><td id="bannerTD"> <div id="bannerContainer"> <div id="bannerBody"> <br /><img src="images/banner.png" border="0" alt="Banner" /> </div> </div> <a href="register.php"><img src="images/signup.png" /></a> <a href="points.php"><img src="images/earn.png" /></a> <a href="vouchers.php"><img src="images/get.png" /></a> </td></tr> <!-- ______________________ /BANNER ___________________--> <div id="contents-top"></div> <div id="contents"> <div class="content-block"> <h1>How does <?php echo $title?> work?</h1><br><br> <a href="register.php<?php echo $referral_string?>"><center><img src="images/step1.png" border="0"><img src="images/step1a.png" border="0"></a><a href="points.php<?php echo $referral_string?>"><img src="images/step2.png" border="0"><img src="images/step2a.png" border="0"><a href="vouchers.php<?php echo $referral_string?>"><img src="images/step3.png" border="0"></center></a> <br> <br> <p> It's easy to use your free time to earn <a href="vouchers.php<?php echo $referral_string?>"><b>rewards</b></a>. While you certainly won't get rich quick or instantly win prizes, if you put in a bit of effort you can earn whatever you want! You can redeem points for online goods or for vouchers such as Amazon, iTunes, ASOS and Xbox Live, the choice is yours. <br><br> While you learn about new products, share information about yourself, or sign up for online services, you earn points. While MOST OFFERS ARE FREE, you will also find cashback shopping and paid/trial offers - a great way to get a deal on your online purchases! <br><br> </p> <h1>Just 3 steps to success!</h1> <p><br> 1. <b>Register:</b> The sign up process takes about 10 seconds, and we'll even give you <font color=#fcbc0c><b><?php echo $bonuspoints ?> FREE BONUS POINTS</b></font> when you <a href="register.php<?php echo $referral_string?>"><b>register</b></a>.<br><br> 2. <b>Earn points:</b> To be able to offer our users FREE gift vouchers to use at online stores such as Amazon and ASOS, you need to earn points. Earning these points are FREE, and you just need to complete a few surveys to get enough points to claim a free voucher. You can also earn points by signing up to some trial offers, but we recommend you stick to the free surveys for now.<br><br> 3. <b>Get Rewards:</b> Once you have earned <?php echo $mainpointsneeded ?> points on <?php echo $title?> you can swap them for REAL products or vouchers, which can be used at online stores/communities. Basically, you can request ANY product or voucher, as long as we can buy it online and send to you via email or shipping. On top of this, if you wish to have something custom ordered, feel free to tell us something what it is and we can always help you out! The rewards you can receive are endless........ </p> <h1>What are points worth?</h1> <p> <br> 10 points = $1.00/£0.50<br> 50 points = $5.00/£2.50<br> 100 points = $10.00/£5.00<br> 200 points = $20.00/£10.00 <br><br> You need <?php echo $mainpointsneeded ?> points before you can redeem them for <a href="vouchers.php<?php echo $referral_string?>">rewards</a>. <br> </p> <h1>How do I know Simple Rewards is legit?</h1> <p>There's no doubt that in today's world fake companies are everywhere. So how do you know Simple Rewards is, in fact, legit? To start, Simple Rewards has already paid out over $10,000 in the last month. This shows not only that we are a legitimate business but also that we are a very active one. If you would like to see more proof of our legitimacy, feel free to check out our <a href="testimonials.php">Testimonials </a> section and read some of the latest testimonials written by Simple Rewards users! </p> <br /> <h1>Reward Ideas</h1> <p> <br /> <img src="images/ps3.png"> <img src="images/giftcards.png"> <img src="images/ipodtouch.png"> </p> <p><center> <p><a href="index.php"><img src="images/largebanner.gif" /><hr width="75%"> <script type=text/javascript language=JavaScript src=http://www.linkreferral.com/networkads2.pl?refid=341046&height=1&width=3&category=money making opportunities&subcategory=services ></script></a></p> </center></p> </div><!--end of contentblock--> </div><!--end of contents--> <div id="contents-bottom"></div> </div><!--end of container--> </div> <?php include("footer.php");?> I registered a few days ago for help on this thread but didn't post again on it now because it has been marked answered and I thought I'd better not bump it. I received help in a way that has been the most encouraging since I began my calendar project. I'm wondering, though, if you would help me understand why I'm not successful at implementing the advice to the point that events are inserting into my calendar.
My testing database has only one table: events and in events, only two columns (other than id): "startdt" and "description". This is a screenshot of how the table's columns are set upL
screenshot.jpg 37.21KB
0 downloads
This is a screenshot of the table content:
screenshot2.jpg 9.35KB
0 downloads
This is my code with the edits added from the support thread:
<?PHP $var = mysql_real_escape_string($_GET['startdt, description']); $con=mysql_connect("localhost","user","password"); // Check connection if (mysql_connect_error()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //select a database to work with $selected = mysql_select_db("mydatabase_",$con) or die("Could not select mydatabase_"); //execute the SQL query and return records $result = mysql_query("SELECT information FROM events WHERE value='$startdt', 'description'"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo $row{'startdt, description'}; } //close the connection mysql_close($con); ?> <!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" /> <link rel="stylesheet" href="css/master.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html" /> <title>Yet Another Test</title> </head> <body> <?php $currMonth = isset($_GET['month']) ? $_GET['month'] : date('n'); $currYear = isset($_GET['year']) ? $_GET['year'] : date('Y'); $today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0; $prevMonth = $currMonth==1 ? 12 : $currMonth-1; $nextMonth = $currMonth==12? 1 : $currMonth+1; $prevYear = $currMonth==1 ? $currYear-1 : $currYear; $nextYear = $currMonth==12? $currYear+1 : $currYear; $day1 = mktime(0,0,0,$currMonth,1,$currYear); $dim = date('t', $day1); $dayN = mktime(0,0,0,$currMonth,$dim,$currYear); $dow1 = (date('w',$day1)+0) % 7; $dowN = (date('w',$dayN)+0) % 7; $calHead = date('F Y',$day1); echo <<<EOT <div class="calwrapper"> <div class="caltitle"><h1>Calendar</h1></div> <div class="container"> <div class="fnl first"></div> <div class="adjust"></div> <div class="fnl last"></div> </div> <div class="caldisplay"> <table cellspacing="0"> <tr> <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td> <td colspan="5" class="adjust">$calHead</td> <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td> </tr> <tr> <th class="we">Sun</th> <th class="wd">Mon</th> <th class="wd">Tue</th> <th class="wd">Wed</th> <th class="wd">Thu</th> <th class="wd">Fri</th> <th class="we">Sat</th> </tr> <tr> EOT; for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>"; $c = $dow1; for ($d=1; $d<=$dim; $d++, $c++) { if ($c%7==0) echo "</tr><tr>"; $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd'; $st = ($d == $today) ? "style='padding: 0px;'" : ''; echo "<td class=\"$cl\" $st>\n"; echo "$d" ; echo "</td>\n"; } while ($c++ % 7 != 0) echo '<td class=\"hd\"> </td>'; echo "</tr></table>\n"; echo '</div></div>'; // calander entries. Use the date as the key (in YYYY/MM/DD format) $entries = array( '2014/8/16' => array( 'Event', ), ); for ($d=1; $d<=$dim; $d++, $c++) { if ($c%7==0) echo "</tr><tr>"; $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd'; $st = ($d == $today) ? "style='padding: 0px;'" : ''; echo "<td class=\"$cl\" $st>\n"; echo "$d" ; echo "</td>\n"; } // construct the date, this will be used to check to if the key exists in the $entries array $dateKey = "$currYear/$currMonth/$d"; // check if the key exists in the $entries array if(array_key_exists($dateKey, $entries)) { // for each event, list it in a seperate tool tip foreach($entries[$dateKey] as $entry) { echo '<div class="has-tooltip"> Event <span class="tooltip">'.$entry.'</span> </div>'; } } ?> </body> </html>I am not getting any errors in the PHP Code Checker (although I am receiving the notice that these functions are now deprecated): mysql_close() mysql_connect() mysql_fetch_array() mysql_query() mysql_real_escape_string() mysql_select_db() When I upload my page to the server, everything seems fine, except that no information is added to the table. When I check the page source, I see this: <!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" /> <link rel="stylesheet" href="css/master.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html" /> <title>Yet Another Test</title> </head> <body> <div class="calwrapper"> <div class="caltitle"><h1>Calendar</h1></div> <div class="container"> <div class="fnl first"></div> <div class="adjust"></div> <div class="fnl last"></div> </div> <div class="caldisplay"> <table cellspacing="0"> <tr> <td class="hd"><a class="cal_button" href="/1cal/calendar.php?year=2014&month=7"> Prev </a></td> <td colspan="5" class="adjust">August 2014</td> <td class="hd"><a class="cal_button" href="/1cal/calendar.php?year=2014&month=9"> Next </a></td> </tr> <tr> <th class="we">Sun</th> <th class="wd">Mon</th> <th class="wd">Tue</th> <th class="wd">Wed</th> <th class="wd">Thu</th> <th class="wd">Fri</th> <th class="we">Sat</th> </tr> <tr><!--DEBUG: year=$currYear and month=$currMonth<hr/--><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="hd"> </td><td class="we" > 1</td> <td class="we" > 2</td> </tr><tr><td class="wd" > 3</td> <td class="wd" > 4</td> <td class="wd" > 5</td> <td class="wd" > 6</td> <td class="wd" > 7</td> <td class="we" > 8</td> <td class="we" > 9</td> </tr><tr><td class="wd" > 10</td> <td class="wd" > 11</td> <td class="wd" > 12</td> <td class="wd" > 13</td> <td class="wd" > 14</td> <td class="we" style='padding: 0px;'> 15</td> <td class="we" > 16</td> </tr><tr><td class="wd" > 17</td> <td class="wd" > 18</td> <td class="wd" > 19</td> <td class="wd" > 20</td> <td class="wd" > 21</td> <td class="we" > 22</td> <td class="we" > 23</td> </tr><tr><td class="wd" > 24</td> <td class="wd" > 25</td> <td class="wd" > 26</td> <td class="wd" > 27</td> <td class="wd" > 28</td> <td class="we" > 29</td> <td class="we" > 30</td> </tr><tr><td class="wd" > 31</td> <td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td><td class=\"hd\"> </td></tr></table> </div></div></body> </html>I don't have an understanding of what the Debug is telling me although I note the number "1" within the tag and find that interesting because on those occasions, earlier today, when the file upload would result in a white page, viewing the page source would reveal nothing but the numeral "1" in the upper left top. Are the deprecated functions enough to cause the event not to insert into the calendar? I'd appreciate any help in sorting why I'm not succeeding. As you see so often around here, I'm not a coder. I'm just forced into a position to have to fend for myself, as of late, and so I'm trying to learn what I can. Thank you for any help. Edited by Izzy-B, 15 August 2014 - 07:24 PM. I am trying to implement what I call private uploads. Basically, users can check a box to indicate they want their file "private" If so, the upload location is then (exampled as): _domain_/private-folder/$randomfolder Upon uploading their file, the random folder is created, their file moved to the directory, the upload information stored to the database, .htaccess file is created like so: info to add to new .htaccess: Code: [Select] <files "*.*"> Deny from All </files> <files "*.*"> Allow from $domains </files> the string $domains is the domains they enter each seperated by a new line in a form textarea. The problem - how can I make sure this is safe. i.e. I want the string to be obviously proofed with php so that no matter what they input, only domains will be outputted. I don't need code written for me (maybe), I'm just unsure of the necessary methods I should use. Hello. Through MySQL, I created a database using the following code: Code: [Select] create database auth; use auth; create table authorized_users ( name varchar(20), password varchar(40), primary key (name) ); insert into authorized_users values ( 'username', 'password' ); insert into authorized_users values ( 'testuser', sha1('password') ); grant select on auth.* to 'webauth' identified by 'webauth'; flush privileges; Then I used the following code to set up a simple log in page. Code: [Select] <?php $name = $_POST['name']; $password = $_POST['password']; if ((!isset($name)) || (!isset($password))) { //Visitor needs to enter a name and password ?> <h1>Please Log In</h1> <p>This page is secret.</p> <form method="post" action="secretdb.php"> <p>Username: <input type="text" name="name"></p> <p>Password: <input type="password" name="password"></p> <p><input type="submit" name="submit" value="Log In"></p> </form> <?php } else { // connect to mysql $mysql = mysqli_connect("localhost", "webauth", "webauth"); if(!$mysql) { echo "Cannot connect to database."; exit; } // select the appropriate database $selected = mysqli_select_db($mysql, "auth"); if(!$selected) { echo "Cannot select database."; exit; } // query the database to see if there is a record which matches $query = "select count(*) from authorized_users where name = '".$name."' and password = sha1('".$password."')"; $result = mysqli_query($mysql, $query); if(!$result) { echo "Cannot run query."; exit; } $row = mysqli_fetch_row($result); $count = $row[0]; if ($count > 0) { // visitor's name and password combination are correct echo "<h1>Here it is!</h1> <p>I bet you are glad you can see this secret page.</p>"; } else { // visitor's name and password combination are not correct echo "<h1>Go Away!</h1> <p>You are not authorized to use this resource.</p>"; } } ?> When I open up this page, above "Please Log In", I get this error: Notice: Undefined index: name in C:\xampp\htdocs\learning\secretdb.php on line 2 Notice: Undefined index: password in C:\xampp\htdocs\learning\secretdb.php on line 3 Moreover, when I type in an authorized username and password, I get another error: Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'webauth'@'localhost' (using password: YES) in C:\xampp\htdocs\learning\secretdb.php on line 19 Cannot connect to database. Does anyone know what I'm doing wrong? I'm fairly new to PHP and MySQL and I'm pretty stuck. Thanks. So I'm implementing a ratings system into my site, the problem here though is my WHILE loop for the voting part of the rating system seems to be bugged. The SQL queries that are used for this script work, the problem seems to be that the $rating variable used to start the while loop never seems to contain anything - I've tried echoing it to confirm this fact. Can anyone see what I've done wrong in this script? Code: [Select] <?php include 'connect.php'; session_start(); $_SESSION['username']; $username = $_SESSION['username']; $member = $_GET['usr']; if(!(isset($_SESSION['login']) && $_SESSION['login']!= " ")){ header("Location: login.php"); } $tablename = 'usr_test'; $sql1 = "SELECT * FROM $tablename WHERE usr = '$member'"; $result1 = mysql_query($sql1) or die (mysql_error()); $display = mysql_fetch_row($result1); $newline = "\n"; ?> <html> <h1>User Profile</h1> <body> <div ="userprofile"> Username: <?php echo $member; ?> <br></br> Email: <?php echo $display[3]; ?> <br></br> University: <?php echo $display[4];?> <br></br> Subject: <?php echo $display[5];?> <br></br> </div> <div ="rating"> <?php while($rating = mysql_fetch_array($result1)) { if ($rating['rating'] != 0) $curr = $rating['total'] / $rating['rating']; else $curr = 0; echo "Rating: ". round($curr, 1) . "<br>"; echo "Rate this seller: "; echo "<a href=".$_SERVER['PHP_SELF']."&mode = vote & voted =1&id =".$rating[usr].">Vote 1</a> | "; echo "<a href=".$_SERVER['PHP_SELF']."&mode = vote & voted =2&id=".$rating[usr].">Vote 2</a> | "; echo "<a href=".$_SERVER['PHP_SELF']."&mode = vote & voted =3&id=".$rating[usr].">Vote 3</a> | "; echo "<a href=".$_SERVER['PHP_SELF']."&mode =vote & voted =4&id=".$rating[usr].">Vote 4</a> | "; echo "<a href=".$_SERVER['PHP_SELF']."&mode = vote & voted =5&id=".$rating[usr].">Vote 5</a><p>"; } ?> </div> <div> </html> |