Jump to content

huisjames

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male
  • Location
    Rainy Seattle

huisjames's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. So I tried some more and this now displays on the page. function query() { global $result; $row = mysql_fetch_array($result); $return = $row['City'].$row['Year'].$row['Make']; return $return; } echo query(); But when I receive the email it is empty. Here is the code of PHPMailer I'm using (see $mail->Body line): require(".\PHPMailer\class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP //IsSMTP(); // send via SMTP $mail->SMTPSecure = "tls"; // sets the prefix to the server $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server $mail->Port = 587; // set the SMTP port for the GMAIL server) $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "myemail@gmail.com"; // SMTP username $mail->Password = "mypassword"; // SMTP password $webmaster_email = "username@domain.com"; //Reply to this email ID $email="myemail@gmail.com"; // Recipients email ID $name="Bob"; // Recipient's name $mail->From = $webmaster_email; $mail->FromName = "Me"; $mail->AddAddress($email,$name); $mail->AddReplyTo($webmaster_email,"Webmaster"); $mail->WordWrap = 50; // set word wrap //$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment $mail->IsHTML(true); // send as HTML $mail->Subject = "This is the subject"; $mail->Body = "Thank you: ".query().""; $mail->AltBody = "This is the body when user views in plain text format"; //Text Body if(!$mail->Send( )) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; }
  2. Hi thorpe, Thanks for the tips. I tried putting your code into a function and simplified it to see if I can pass even one variable: function query($result) { $row = mysql_fetch_array($result); $return = "Year: ".$row['Year']; return $return; } echo query($result); Expected: Show the year or return an error Actual: No value shown and no error. Questions: 1. Could it be that mysql_fetch_array needs a while loop to display results? 2. I also tried this and no luck: function query() { global $result; $row = mysql_fetch_array($result); $return = "Year: ".$row['Year']; return $return; } echo query(); 3. I found a work-around which is to declare a variable for each row of SQL output within the while loop. I.e. $City = $row['City']; $Year = $row['Year']; and just call these variables individually for the mail body. But it doesn't seem to be the most efficient way to code. I'm just looking for the smartest way to do this. Perhaps this method is fine? Thanks so much
  3. Good feedback thrope. Expected result: Prints below in the mail body: echo "<b>Date: ".$date."</b><p />"; echo "City: ".$row['City']."<p />"; echo "Calendar: ".$Calendar."<p />"; echo '<img src="img/large/'.$row['Img'].'" border="1" /><p />'; echo "Year: ".$row['Year']."<p />"; echo "Make: ".$row['Make']."<p />"; echo "Model: ".$row['Model']."<p />"; echo "Shift: ".$row['Shift']."<p />"; echo "Distance: ".$row['Distance']."<p />"; echo "Price: ¥".$row['Price']."<p />"; echo "Payment method: ".$Paytype."<p />"; Actual result 1: I tried $mailbody = "Here is your email confirmation: ".$object->query()."" but the web page now prints two copies and nothing shows in the email. Actual result 2: If I do: $mail = $object->query(); $mailbody = $mail; It returns me with Catchable fatal error: Object of class PHPMailer could not be converted to string
  4. I have a typical user registration/purchase confirmation scenario. I need to send out a confirmation email but I'm not sure how to include mysql_fetch_array into the body of the mail. *WAMPServer 2.0 *PHP 5.3.0 *MySQL 5.1.36 *Using PHPMailer script I found and sending via Gmail SMTP server (sent mail with text works) *The text contains Simplified Chinese What's wrong with my code? class database{ function query() { $Paytype= $_POST['Cardtype']; $CarID = $_POST['CarID']; $Calendar = $_POST['Calendar']; //1. Connect/Login to MySQL $con = mysql_connect("localhost", "fakeuser", "fakeuser"); //echo !$con ? 'Could not connect: '.mysql_error() : 'Connection success!<p />'; //2. Tells which db to connect to mysql_select_db("carshare", $con); /*On the MySQL side, set two session control variables: character_set_client=utf8 and character_set_connection=utf8 when saving input text to the database table. This is to tell MySQL server that my SQL statement is encoded as UTF-8 and keep it as UTF-8 when executing the statement. */ mysql_query("SET character_set_client=utf8", $con); mysql_query("SET character_set_connection=utf8", $con); //When retrieving text data from MySQL, I need to set one session control variable: //character_set_results=utf8. This is to tell MySQL server that result set must be sent back in UTF-8 encoding. mysql_query("SET character_set_results=utf8", $con); //3. Queries the db $result = mysql_query(" SELECT cars.CarID, cars.Img, cars.Year, cars.Make, cars.Model, cars.City, cars.Shift, cars.Distance, cars.Price FROM cars WHERE cars.CarID=".$CarID." ") or die(mysql_error()); $date = date('H:i, jS F Y'); $resultcount = mysql_num_rows($result); //4. Print results in an array while($row = mysql_fetch_array($result)) { echo "<b>Date: ".$date."</b><p />"; echo "City: ".$row['City']."<p />"; echo "Calendar: ".$Calendar."<p />"; echo '<img src="img/large/'.$row['Img'].'" border="1" /><p />'; echo "Year: ".$row['Year']."<p />"; echo "Make: ".$row['Make']."<p />"; echo "Model: ".$row['Model']."<p />"; echo "Shift: ".$row['Shift']."<p />"; echo "Distance: ".$row['Distance']."<p />"; echo "Price: ¥".$row['Price']."<p />"; echo "Payment method: ".$Paytype."<p />"; } //5. Close connection with db $close = mysql_close($con); } } $object = new database(); $object->query();
  5. I need to configure my SMTP mail port so I can use mail() function to send out e-mails. However, I am confused as to which php.ini to configure. I see four files when I do a search under C:\WAMP\ php.ini (C:\wamp\bin\apache\Apache2.2.11\bin) php.ini (C:\wamp\bin\php\php5.3.0) php.ini-development (C:\wamp\bin\php\php5.3.0) php.ini-production (C:\wamp\bin\php\php5.3.0) Thanks
  6. Should we always use urlencode() when passing values through GET? If not, when is it should we NOT use it? Thanks
  7. Thanks Fenway. I decided to just enter them in SQL instead.
  8. Hi, I have rows and rows of data in Chinese characters in Excel .xlsx file. I need to import them into MySQL. I tried saving .xlsx as .csv but it the characters explode. Doesn't CSV support UTF-8? I tried changing the font to "Unicode" and that didn't help either. Thanks
  9. Thanks to you BlueSky. I figured it out. Resolved.
  10. Hi, How do I generate a Google Map from user registration form? For example, user enters username, password, and address. I want to show the username, address + corresponding map on following confirmation page. I have already used static API to render the map as an image, but this is hard-coded. I don't know how to pass the address into the address param. Any help would be much appreciated. Thanks!
  11. I haven't learned how to use includes or ssi yet. But I just found a handy feature in Dreamweaver that allows user to create templates and updates the pages that were created from the templates automatically. Thanks thrope.
  12. Hi, Is there a way to reuse header and footer for multiple new html/php pages in case I change the content of the header/footer in the future? Content include links to About Us, Press, Privacy, etc... I have the CSS styles saved in an external CSS stylesheet. But content may still change and I would hate to copy and paste repeatedly. Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.