I am working on a splash page which contains a form. When the form is Submitted my add.php writes the form input fields to a SQL server, then it is supposed to send an html email to the person who filled out the form.
Issue #1: The email is received, but it displays the html markup; not the formatted version of the email.
Issue #2: The "From" field is being populated with "text/html" and displays the webserver: tribeca.websitewelcome.com. It is not showing the specified email.
Here is the contents of add.php
<?php
$name=$_POST['Name'];
$email=$_POST['Email'];
$to = $_POST['Email'];
$subject = 'Company Name Webinar Contact';
$message = '<!DOCTYPE html>
<html>
<head>
<title>Email</title>
</head>
<body style="background-color: #e9e9e9;">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr> <td style="width:600px;"> </td> </tr>
<tr> <td> <table cellspacing="0" cellpadding="0" width="600px" border="0" style="background-color: #fff;margin:0 auto;border:solid 10px #fff;font-family: lucida grande, sans-serif;">
<tr> <td style="height:100px;"> <center> <img src="eq-logo.jpg" /> </center> </td> </tr>
<tr style="height:1px; background-color:#dcdcdc"> <td > </td> </tr>
<tr style="height:1px; background-color:#f1f5ee"> <td > </td> </tr>
<tr style="height:100px;"> <td > <h1 style="color:#e10621;">Thank you for your enquiry!</h1> <h3>Someone from our team will contact you shortly.</h3> <p style="line-height:28px;">We've helped hundreds achieve their financial dreams and look forward to showing YOU how to turn YOUR common "cents" into dollars. Please take a few moments to check out the other areas of our website. </p> <p><b>The Company Name Team</b></p> </td> </tr>
</table> </td> </tr>
<tr> <td> <center> <img src="bottom-shadow.png" /> </center> </td> </tr>
</table>
</body> </html>
';
$headers = 'MIME-Version: 1.0' . '\r\n';
$headers .= 'Content-type:text/html;charset=iso-8859-1' . '\r\n';
$headers .= 'From: <donotreply#companyname.com.au>' . "\r\n";
// Connect
mysql_connect("localhost", "db_user", "user_password") or die(mysql_error()) ;
mysql_select_db("db_name") or die(mysql_error()) ;
// Write
mysql_query("INSERT INTO `table_name` VALUES ('$name', '$email')") ;
// Email
mail($to,$subject,$message,$headers);
header('Location: http://companyname.com.au');
exit();
?>
Additional Notes:
I have tried separating the 'message' out into line by line html as in chris coyiers html email tut with no luck. Here you see the html in its entirety in the message area.
It's your quotes! Use double quotes for your \r\n lines:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html;charset=iso-8859-1' . "\r\n";
$headers .= 'From: <donotreply#companyname.com.au>' . "\r\n";
Related
Please, help me grab information from this structure:
<table id="id1" class="class1">
<tbody>
<tr id="id2">
<td>
<span class="class2">
"header text"
</span>
</td>
<td id="d" style="width:10px;">
<img style="width:10px;" src="/images/img1.gif">
</td>
<td id="r" style="width:40%;">
<span class="class2">
<nobr>Headings:</nobr>
</span>
</td>
</tr>
<tr>
<td>
<table class="class1" style="width:100%;">
<tbody>
<tr>
<td width="300" valign="top"></td>
</tr>
<tr>
<td style="padding:0px;">
<div>
<b>Address: </b>
Address text
</div>
<div>
<b>Tel.: </b>
250-1729
</div>
<br>
</td>
</tr>
</tbody>
</table>
</td>
<td>
<img src="/images/img.gif">
</td>
<td>
heading1
<br>
heading2
<br>
heading3
<br>
</td>
</tr>
</tbody>
I want to get:
header text
Address text
Tel. number
but I don't understand, how can I get it with PowerShell.
Firstly, I get this table
$address = "http://address.com"
$page = Invoke-WebRequest $address
$table = $($page.parsedhtml.getElementsByTagName("table") | Where { $_.id -eq 'id1' })
What's next?
How can I call table's children and get their texts?
This is my decision:
$address = "http://address.com"
$page = Invoke-WebRequest $address
$table = $($page.parsedhtml.getElementById("id1")
$tr = $table.getElementsByTagName('tr') | Where { $_.id -eq 'id2' }
$name=($tr.getElementsByTagName('a') | select -First 1).innertext
$divs=$table.getElementsByTagName('div')
foreach ($div in $divs) {
if ($div.innertext -match "address: ") {$adr=$div.innertext -replace "Address: ",""}
if ($div.innertext -match "Tel.: ") {$tel=$div.innertext -replace "Tel.: ",""}
}
$resultmassive+=[string]::Join(";",$name,$adr,$tel)
p.s. Maybe, it is possible to use PowerShell switch-case construcion instead foreach, but it doesn't works for me.
First and foremost: if your elements have an ID use getElementById() instead of getElementsByTagName() with an additional filter. That will give you the correct table (or other element) right away.
When you have the (parent) element you can get nested elements by calling getElementById(), getElementsByTagName(), etc. on the parent:
$nestedTables = $table.getElementsByTagName('table')
In your case you want to get
the child element with the ID id2 and then the (grand)child <a> element (for the header text)
$tr = $table.getElementById('id2')
$tr.getElementsByTagName('a')
the <div> elements in the nested table (for the address and phone number):
$table.getElementsByTagName('div')
I have created a php file called search.php. I want to show the result on a table
I want a table structure like this.
__________________________
| |________________|
| |________________|
| |________________|
|________|________________|
|________________|
|________________|
On the left side I want to place a picture which will be obtained from database and to the right I will place information about the student photo.
Could you write a code. Can we separate photo and the information column by a vertical line only.(if yes,HOW ?? )
<table>
<tr>
<td rowspan="4" style="border-right: 1px solid black">
<img src"whatever.png" alt="" />img
</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>4</td>
</tr>
<tr>
<td rowspan="2">
</td>
<td>5</td>
</tr>
<tr>
<td>6</td>
</tr>
</table>
but really: learn html an get used to the boxed model, that is: use divs
<?php
$sql = "Select FROM * `yourtablename` where `id` = 'theidofthestudent'";
if(!mysql_query($sql)){
die(mysql_error());
} else {
echo "<table border="1px" style="text-align:center;" align="justify">";
echo "<th>Photo of student</th>";
echo "<th>Name of the student</th>";
echo "<th>Student Detials</th>";
while($row = mysql_fetch_array($sql)){
echo "<tr>";
echo "<td style="float:left;">' . $row['student_pic'] . "</td>";
echo '<td style="float:right;">' . $row['student_name'] . "</td>";
echo '<td style="float:right;">' . $row['student_details'] . "</td>";
echo "</tr>"
} echo "</table>";
}
?>
This is supposed to be a simple high scores table. but everytime it pulls another player from the database it looks like this.
(table headers)
player
(table headers)
player
(table headers)
player
and so on you get the picture... I want it to just show the header one time at the top of the list of players... I had it working at one time and don't remember what I changed that caused it to do this, does anyone know how to fix it?
Here is my code:
<?php
$result = mysql_query("SELECT * FROM users ORDER BY explores DESC LIMIT 20;")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
?>
<table class="reg-box" style="width: 600px; text-align: center;" align="center" cellspacing="5">
<tbody>
<tr>
<th colspan="2">Trainer</th>
<th colspan="2">Explores</th>
</tr>
<tr>
<td colspan="2"><?php echo "".$row['username'].""; ?></td>
<td colspan="2"> <?php echo $row['explores']; ?></td>
</tr>
</tbody>
</table>
<?php } ?>
The problem with your code was the table is getting created in the loop, leading to the multiple headers. Instead remove the creation of the table from the while loop and then try to update all the result set you get from the query you fired in a loop. Try this.
$result = mysql_query("SELECT * FROM users ORDER BY explores DESC LIMIT 20;")
or die(mysql_error());
?>
<table class="reg-box" style="width: 600px; text-align: center;" align="center" cellspacing="5">
<tbody>
<tr>
<th colspan="2">Trainer</th>
<th colspan="2">Explores</th>
</tr>
<?php
while($row = mysql_fetch_array( $result )) {
<tr>
<td colspan="2"><?php echo "".$row['username'].""; ?></td>
<td colspan="2"> <?php echo $row['explores']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
I am not a trained programmer. Whatever I learned is by myself from the net. Please excuse if you find my code and question very amateurish.
I am trying to call matches of buyers against sellers data from the database and automatically mail them their matches.
When I run this code on my system with EasyPhp, it says 'Query was empty". And when I run this on my server, it says "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 " where am I going wrong ?
<?php
include('adminmaster.htm');
Echo "<center>Mail Matching Properties</center><br><br>";
mysql_connect("localhost", "username","password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$query= 'SELECT*FROM clientdata WHERE email != " " AND Transaction="Buyer"';
$result=mysql_query($query);
echo mysql_error();
if (!$result){ die("No Buy results");}
$matchrows=mysql_num_rows($result);
if($matchrows==0){ die("No Buy results");}
while($info = mysql_fetch_array($result))
$Price1= $info['Price']+($info['Price']*10/100);
$Price2 = $info['Price']-($info['Price']*10/100);
$una=$info['username'];
$query2='SELECT*FROM clientdata WHERE email!=" " AND Transaction="Seller"';
$result2=mysql_query($query2);
echo mysql_error();
$matchrows2=mysql_num_rows($result2);
if($matchrows2==0){ die("Sell Data Not Found");}
if(!$result2)
{die("Sell Data Not Found");}
while($info2=mysql_fetch_array($result2))
{
if ($info['Detail']==$info2['Detail'])
{
if ($info['Location']==$info2['Location'])
{
if ($Price1 >= $info2['Price'])
{
if ($Price2 <= $info2['Price'])
{
if ($info['username']!=$info2['username'])
{
echo mysql_error();
echo "<table width=600 border = 1 style='text-align:left';>
<tr>
<td><b>Clients</b></td>
<td><b><font color='maroon'>BUYER</font></b></td>
<td><b><font color='maroon'>SELLER</font></b></td>
</tr>
<tr>
<td><b>Date Posted:</b></td>
<td>$info[Date]</td>
<td>$info2[Date]</td>
</tr>
<tr>
<td><b>Title:</b></td>
<td>$info[propheading]</td>
<td>$info2[propheading]</td>
</tr>
<tr>
<td><b>Transaction:</b></td>
<td>$info[Transaction]</td>
<td>$info2[Transaction]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Detail:</b></td>
<td style='background-color:lightgrey'>$info[Detail]</td>
<td style='background-color:lightgrey'>$info2[Detail]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Price:</b></td>
<td style='background-color:lightgrey'>$info[Price]</td>
<td style='background-color:lightgrey'>$info2[Price]</td>
</tr>
<tr>
<td><b>Additional Data:</b></td>
<td>$info[AdditionalData]</td>
<td>$info2[AdditionalData]</td>
</tr>
<tr>
<td><b>Location:</b></td>
<td>$info[Location]</td>
<td>$info2[Location]</td>
</tr>
<tr>
<td><b>Agent/Individual:</b></td>
<td>$info[Agent_Ind]</td>
<td>$info2[Agent_Ind]</td>
</tr>
<tr>
<td><b>Name:</b></td>
<td>$info[Title] $info[firstname] $info[lastname]</td>
<td>$info2[Title] $info2[firstname] $info2[lastname]</td>
</tr>
<tr>
<td><b>Phone:</b></td>
<td>$info[Phone]</td>
<td>$info2[Phone]</td>
</tr>
<tr>
<td><b>Email:</b></td>
<td>$info[Email]</td>
<td>$info2[Email]</td></tr>
</table>";
$tomail=$info2['Email'];
if ($tomail=="anitgopinath#gmail.com"|$tomail=="anit#landshoppe.com"|$tomail=="info#landshoppe.com") {continue;}
$headers ="From:info#landshoppe.com"."\r\n";
$headers .='Bcc:anit#landshoppe.com'."\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$subject ="You have a Property Match !";
$message="<html></head><body>
<table width=600 border = 1 style='text-align:left';>
<caption><b><font color='maroon'>YOUR PROPERTY MATCH!</font></b></caption>
<tr>
<td><b>Date Posted:</b></td>
<td>$info[Date]</td>
</tr>
<tr>
<td><b>Title:</b></td>
<td>$info[propheading]</td>
</tr>
<tr>
<td><b>Transaction:</b></td>
<td>$info[Transaction]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Detail:</b></td>
<td style='background-color:lightgrey'>$info[Detail]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Price:</b></td>
<td style='background-color:lightgrey'>$info[Price]</td>
</tr>
<tr><td><b>Additional Data:</b></td><td>$info[AdditionalData]</td></tr>
<tr><td><b>Location:</b></td><td>$info[Location]</td></tr>
<tr><td><b>Agent/Individual:</b></td><td>$info[Agent_Ind]</td></tr>
<tr><td><b>Name:</b></td><td>$info[Title] $info[firstname] $info[lastname]</td></tr>
<tr><td><b>Phone:</b></td><td>$info[Phone]</td></tr>
<tr><td><b>Email:</b></td><td>$info[Email]</td></tr>
</table></body><html>";
echo $tomail."<br>";
echo "$message"."<br>";
$mailresult=mysql_query(mail($tomail,$subject,$message,$headers));
if ($mailresult){echo "Mailed<br>";}else{echo "Not Mailed !<br>";}
echo "**********************************Seller Match**************************************************<br>";
$tomail2=$info['Email'];
if ($tomail2=="anitgopinath#gmail.com"|$tomail2=="anit#landshoppe.com"|$tomail2=="info#landshoppe.com"){continue;}
$headers ="From:info#landshoppe.com"."\r\n";
$headers .='Bcc:anit#landshoppe.com'."\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$subject ="You have a Property Match !";
$message="<html></head><body>
<table width=600 border = 1 style='text-align:left';>
<caption><b><font color='maroon'>YOUR PROPERTY MATCH!</font></b></caption>
<tr>
<td><b>Date Posted:</b></td>
<td>$info2[Date]</td>
</tr>
<tr>
<td><b>Title:</b></td>
<td>$info2[propheading]</td>
</tr>
<tr>
<td><b>Transaction:</b></td>
<td>$info2[Transaction]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Detail:</b></td>
<td style='background-color:lightgrey'>$info2[Detail]</td>
</tr>
<tr>
<td style='background-color:lightgrey'><b>Price:</b></td>
<td style='background-color:lightgrey'>$info2[Price]</td>
</tr>
<tr>
<td><b>Additional Data:</b></td>
<td>$info2[AdditionalData]</td>
</tr>
<tr>
<td><b>Location:</b></td>
<td>$info2[Location]</td>
</tr>
<tr>
<td><b>Agent/Individual:</b></td>
<td>$info2[Agent_Ind]</td>
</tr>
<tr>
<td><b>Name:</b></td>
<td>$info2[Title] $info2[firstname] $info2[lastname]</td>
</tr>
<tr>
<td><b>Phone:</b></td>
<td>$info2[Phone]</td>
</tr>
<tr>
<td><b>Email:</b></td>
<td>$info2[Email]</td>
</tr>
</table></body><html>";
echo $tomail2."<br>";
echo "$message"."<br>";
$mailresult2=mysql_query(mail($tomail2,$subject,$message,$headers));
if ($mailresult2){echo "Mailed<br>";}else{echo "Not Mailed !<br>";}
echo "**********************************Buyer Match**************************************************<br>";
}
}
}
}
}
}
}
?>
First of all, when specifying string literals within SQL request you should use single qoutes:
$query= "SELECT*FROM clientdata WHERE email != ' ' AND Transaction='Buyer'";
Don't want to sound rude, but you better redesign your code, it's a mess right now. Start with a simple 'divide and conquer' method: mark each block of code that does ONE and only ONE thing - and separate into a single function (leaving only its call in the main script). You'll instantly notice the difference it'll make in both reading and updating your code.
The error you spoke about is caused by this line:
$mailresult=mysql_query(mail($tomail,$subject,$message,$headers));
... as the result of mail function is boolean. And when converted into string by mysql_query, it's either an empty string or '1'; both of them, of course, are not valid queries. If you need to check the result, it's just...
$mailresult=mail($tomail,$subject,$message,$headers);
And again, the error itself is simple - but it's hidden in your code so good that five or more SO users failed to find it. ) That's why the code needs restructuring.
I'm new to PHP and am trying to scrape data from a website I'm using regular expressions, but locating content rental and details in the div is a problem here is my code. Could someone help me out?
<?php
header('content-type: text/plain');
$contents= file_get_contents('http://www.hassconsult.co.ke/index.php?option=com_content&view=article&id=22&Itemid=29');
$contents = preg_replace('/\s(1,)/','',$contents);
$contents = preg_replace('/ /','',$contents);
//print $contents."\n";
$records = preg_split('/<span class="style8"/',$contents);
for ($ix=1; $ix < count($records); $ix++){
$tmp = $records[$ix];
preg_match('/href="(.*?)"/',$tmp, $match_url);
preg_match('/>(.*?)<\/span>/',$tmp,$match_name);
preg_match('/<div[^>]+class ?= ?"style10"[^>]*>(\s*(<div.*(?2).*<\/div>\s*)*)<\/div>/Us',$tmp,$match_rental);//error is here
print_r($match_url);
print_r($match_name);
print_r($match_rental);
print $tmp."\n";
exit ();
}
//print count($records)."\n";
//print_r($records);
//if ($contents===false)
//print 'FALSE';
//print_r(htmlentities($contents));
?>
Here is a sample of the content
>HILLVIEW CROSSROADS4 BED HOUSE</span></div></td>
</tr>
<tr>
<td width="57%" style="padding-left:20px;"><div align="left" class="style10" style="color:#007AC7;">
<div align="left">
Rental;
USD 4,500
</div>
</div></td>
<td width="43%" align="right"><div align="right" class="style10" style="color:#007AC7;">
<div align="right">
No.
834
</div>
</div></td>
</tr>
<tr>
<td colspan="2" style="padding-left:20px;color:#000000;">
<div align="justify" style="font-family:Arial, Helvetica, sans-serif;font-size:11px;color:333300;">Artistically designed 4 bed (all
ensuite) house on half acre of well-tended gardens. Lounge with fireplace opening to terrace, opulent master suite, family room, study. Good finishes, SQ, carport, extra water storage
and generator. ....Details </div></td>
</tr>
</table></td>
</tr>
</table>
<br>
That website doesn't have good css selectors but it's still not to hard to get it with xpath:
$dom = new DOMDocument();
#$dom->loadHTMLFile('http://www.hassconsult.co.ke/index.php?option=com_content&view=article&id=22&Itemid=29');
$xpath = new DOMXPath($dom);
foreach($xpath->query("//div[#id='ad']/table") as $table) {
// title
echo $xpath->query(".//span[#class='style8']", $table)->item(0)->nodeValue . "\n";
// price
echo $xpath->query(".//div[#class='style10']/div", $table)->item(0)->nodeValue . "\n";
// description
echo $xpath->query(".//div[#align='justify']", $table)->item(0)->nodeValue . "\n";
}