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?
 
KalpanConnect With a Mentor Commented:
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
 
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
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_romychConnect With a Mentor Commented:
<?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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.