PHP MAIL, TABLE....

Hi Experts, Ive got the following code,

What i need it to do is send a table with the following variables

$customer_name
$account_number
$contract_end
$mobile_number

To every person listed in the $string array in the code,

How would i go about sending this list in a neat formatted table to their email address??

i have attached the code.

Many thanks for your time it is greatly Appreciated.


<?php
include 'myphp.php';

$sql = "SELECT customer_name, account_number, mobile_number, end_contract
FROM customer_details 
ORDER BY end_contract ASC";
 $result4=mysql_query($sql);
if($result4) {
	$count=mysql_num_rows($result4);
	while($rows=mysql_fetch_array($result4)){
                // create email message
				$customer_name=$rows['customer_name'];
				$account_number=$rows['account_number'];
				$mobile_number=$rows['mobile_number'];
				$end_contract=$rows['end_contract'];
				// ---------------- SEND MAIL FORM ----------------
$string = "'doug@tlk.co','kate@tlk.co','mark@tlk.co'";
var_dump ($string);
// send e-mail to ...
$to=$string;
	echo "User: $to";
// Your subject
$subject="Contract End Dates";

// From
$header="from: Admin@tlk.co <admin@tlk.co>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://scm-intranet/users/f6030782/FYP/confirmation.php?passkey=$confirm_code";


// send email
$sentmail = mail($to,$subject,$message,$header);

}
}
// if not found 
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your List Has Been Sent To Your Email Address.  <a href='index.php'>Back to main page</a>";
}
else {
echo " Cannot send contract end list  to your e-mail address";
}

?>

Open in new window

LVL 6
NeoAshuraAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KalpanCommented:
you can add the following

// Your message
$message= "<table>";
$message.="<tr><td>Your Comfirmation link</td></tr>";
$message.="<tr><td>Click on this link to activate your account </td></tr>";
$message.="<tr><td>http://scm-intranet/users/f6030782/FYP/confirmation.php?passkey=$confirm_code"</td></tr>";
$message.="</table>";
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NeoAshuraAuthor Commented:
ahh right, thanks. ill give it ago and get back to you/
0
NeoAshuraAuthor Commented:
ok not sure if it worked because i got the following error, would this error be because im using EasyPHP development enviroment??

Warning: mail() [function.mail]: Failed to connect to mailserver at "127.0.0.1" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Users\Database Development\Desktop\EasyPHP-5.3.5.0\www\sendmail.php on line 40
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

KalpanCommented:
check you SMTP port with your php.ini than it should work

[mail function]
; For Win32 only.
SMTP = writehereyoursmtpserver
smtp_port = 25


http://www.phpbuilder.com/board/printthread.php?t=10301360
0
k_romychCommented:
<?php
include 'myphp.php';

$sql = "SELECT customer_name, account_number, mobile_number, end_contract
FROM customer_details 
ORDER BY end_contract ASC";
 $result4=mysql_query($sql);
if($result4) {
	$count=mysql_num_rows($result4);
	$my_table="<table><tr><td>Customer Name</td><td>Account Number</td><td>Mobile Number</td><td>End contract</td></tr>";
	while($rows=mysql_fetch_array($result4)){
                // create email message
                
				$customer_name=$rows['customer_name'];
				$account_number=$rows['account_number'];
				$mobile_number=$rows['mobile_number'];
				$end_contract=$rows['end_contract'];
				$my_table.="<tr><td>$customer_name</td><td>$account_number</td><td>$mobile_number</td><td>$end_contract</td></tr>";
				}
			$my_table.="</table>";
				// ---------------- SEND MAIL FORM ----------------
$string = "'doug@tlk.co','kate@tlk.co','mark@tlk.co'";
var_dump ($string);
// send e-mail to ...
$to=$string;
	echo "User: $to";
// Your subject
$subject="Contract End Dates";

// From
$header="from: Admin@tlk.co <admin@tlk.co>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://scm-intranet/users/f6030782/FYP/confirmation.php?passkey=$confirm_code";
$message.="\n <br/>".$my_table;


// send email
$sentmail = mail($to,$subject,$message,$header);

}

// if not found 
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your List Has Been Sent To Your Email Address.  <a href='index.php'>Back to main page</a>";
}
else {
echo " Cannot send contract end list  to your e-mail address";
}

?>

Open in new window

0
NeoAshuraAuthor Commented:
all it shows is the following in the email message received?

<html><table><tr><td>Customer Name</td><td>Account Number</td><td>Mobile Number</td><td>End contract</td></tr>

How do i get it to show it as a table it comes out as text atm. i have used headers and definded these as the following:

$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";

Ill attach my whole code in the snippet page.
<?php
include 'myphp.php';

$sql = "SELECT customer_name, account_number, mobile_number, end_contract
FROM customer_details 
ORDER BY end_contract ASC";
 $result4=mysql_query($sql);
if($result4) {
	$count=mysql_num_rows($result4);
	$my_table="<html><table><tr><td>Customer Name</td><td>Account Number</td><td>Mobile Number</td><td>End contract</td></tr>";
	while($rows=mysql_fetch_array($result4)){
                // create email message
				$customer_name=$rows['customer_name'];
				$account_number=$rows['account_number'];
				$mobile_number=$rows['mobile_number'];
				$end_contract=$rows['end_contract'];
	}
	$my_table.="</table></html>";
				// ---------------- SEND MAIL FORM ----------------
$string = 'phil@tlk.co';
var_dump ($string);
// send e-mail to ...
$to=$string;
	echo "User: $to";
// Your subject
$subject="Contract End Dates";

// From
$header="from: Admin@tlk.co <admin@tlk.co>";
$headers = "MIME-Version: 1.0rn"; 
$headers .= "Content-type: text/html; charset=iso-8859-1rn"; 
 

// Your message

$message="Your Contract End list \r\n";
$message.="List of all contracts ending within 60 days. \r\n";
$message.=$rows['customer_name'];
$message.=$rows['mobile_number'];
$message.=$rows['account_number'];
$message.=$rows['end_contract'];
$message.="\n <br/>".$my_table;


// send email
$sentmail = mail($to,$subject,$message,$header,$headers);

}

// if not found 
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.  <a href='index.php'>Back to main page</a>";
}
else {
echo " Cannot send Confirmation link to your e-mail address";
}

?>

Open in new window

0
k_romychCommented:
try it like this
<?php
include 'myphp.php';

$sql = "SELECT customer_name, account_number, mobile_number, end_contract
FROM customer_details 
ORDER BY end_contract ASC";
 $result4=mysql_query($sql);
if($result4) {
	$count=mysql_num_rows($result4);
	$my_table="<table><tr><td>Customer Name</td><td>Account Number</td><td>Mobile Number</td><td>End contract</td></tr>";
	while($rows=mysql_fetch_array($result4)){
                // create email message
				$customer_name=$rows['customer_name'];
				$account_number=$rows['account_number'];
				$mobile_number=$rows['mobile_number'];
				$end_contract=$rows['end_contract'];
	}
	$my_table.="</table></body></html>";
				// ---------------- SEND MAIL FORM ----------------
$string = 'phil@tlk.co';
var_dump ($string);
// send e-mail to ...
$to=$string;
	echo "User: $to";
// Your subject
$subject="Contract End Dates";

// From
$header="from: Admin@tlk.co <admin@tlk.co>";
$headers = "MIME-Version: 1.0rn"; 
$headers .= "Content-type: text/html; charset=iso-8859-1rn"; 
 

// Your message

$message="<html><body> Your Contract End list \r\n";
$message.="List of all contracts ending within 60 days. \r\n";
//$message.=$rows['customer_name'];
//$message.=$rows['mobile_number'];
//$message.=$rows['account_number'];
//$message.=$rows['end_contract'];
$message.="\n <br/>".$my_table;


// send email
$sentmail = mail($to,$subject,$message,$header,$headers);

}

// if not found 
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.  <a href='index.php'>Back to main page</a>";
}
else {
echo " Cannot send Confirmation link to your e-mail address";
}

?>

Open in new window

0
NeoAshuraAuthor Commented:
that did not work either,

Im now using this code,

This code exports the data CORRECTLY but does not format it in a table which im trying to do?
<?php
include 'myphp.php';

$sql = "SELECT customer_name, account_number, mobile_number, end_contract
FROM customer_details 
ORDER BY end_contract ASC";
 $result4=mysql_query($sql);
if($result4) {
	$count=mysql_num_rows($result4);
	$my_table="<html><table><tr><td>Customer Name</td><td>Account Number</td><td>Mobile Number</td><td>End contract</td></tr>";
	 $to = "phil@tlk.co";
  $subject = "Results from query";
  $body = "<table border='1'>";
  $body .="<tr>";
  $body .="<th>Customer Name:</th>";
  $body .="<th>Account Number:</th>";
  $body .="<th>Mobile Number:</th>";
  $body .="<th>End Contract:</th>";
  $body .="</tr>";
 while($row = mysql_fetch_array($result4)){
  $body .="<tr>";
  $body .="<td>" . $row['customer_name'] . "</td>";
  $body .="<td>" . $row['account_number'] . "</td>";
  $body .="<td>" . $row['mobile_number'] . "</td>";
  $body .="<td>" . $row['end_contract'] . "</td>";
  $body .="</tr>";
  }
  $body .="</table>";
  ;
  $header = "From: admin@tlk.co";
$headers = "MIME-Version: 1.0rn"; 
$headers .= "Content-type: text/html; charset=iso-8859-1rn"; 
 
// send email
$sentmail = mail($to,$subject,$body,$header,$headers);

}

// if not found 
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.  <a href='index.php'>Back to main page</a>";
}
else {
echo " Cannot send Confirmation link to your e-mail address";
}

?>

Open in new window

0
NeoAshuraAuthor Commented:
problem solved. I just put the content type into my header in the send form.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.