473,322 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Sending mails with PHP with tables

Hello,
I´m trying to build a php program to send emails with tables with variables into thems. I explain: the body of emails contens into a table 2x2 and the first line have titles: (Name, Lastname) and the second line, variables from a Mysql like $name and $lastname.
Some one can help me to acomplish that! I´m lost.
Thanks
guillermo
Jul 27 '05 #1
4 3050
Niheel
2,460 Expert Mod 2GB
Here is a rough example of some code:
Expand|Select|Wrap|Line Numbers
  1.  
  2. // asks database for all members and their information example e-mail, first name, last name
  3. $result = mysql_query("SELECT * FROM members");
  4.  
  5. //run a loop to go through all members
  6. while ($row = mysql_fetch_array ($result)){
  7.     $first = $row[firstname];
  8.     $last = $row[lastname];
  9.     $email = $row[email];
  10.  
  11.     // this is where you would have a template for your table/html
  12.     $html = "$first, $last, $email";   // example, i'm sure ur e-mail would be different
  13.  
  14.     // use mail function to mail out
  15.    mail();  // use php.net to see what the mail function required inputs are
  16. }
  17.  
There are other things u need to take in consideration, like subscriber list. If the list is long then you need to run this script in CLI mode. Also you need to to pay attention to how html e-mails are sent. HTML e-mails need different mime types.

Quick search on "MIME e-mail PHP mail" should get you what you are looking for.

Hope that helps.
Jul 28 '05 #2
Hi,
Thanks for your fast response.
All you code it´s very usefull for me, but i want to explain better my situation.
I include some code:
$mensaje = '
<html>
<head>
<title>Recordatorio de Cumplea&ntilde;os para Agosto</title>
</head>
<body>
<p>&iexcl;Aqu&iacute; est&aacute;n los cumplea&ntilde;os que llegan en Agosto!</p>
<table>
<tr>
<th>Persona</th><th>D&iacute;a</th><th>Mes</th><th>A&ntilde;o</th>
</tr>
<tr>
<td>Juan</td><td>3</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sandra</td><td>17</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
This inserts a 4 colums with 3 lines (Titles ans Data) like this
Persona Día Mes Año
Juan 3 August 1970
Sandra 17 August 1973
I´m looking to put all data into a table with borders, colors, etc and i´m trying to replace the names and dates to variables lik $name, $date, etc.
It´s possible to do that? I´m checked some many documentation (PHP site, web forums but I cannot find and example o any tools to do that.
Thanks a lot .
guillermo
Jul 28 '05 #3
Hello there,
I too am having a somewhat similar problem and would very much appreciate some assistance. Through PHP, I have already set up my Flash actionscript to pass info and variables onto a MySQL database that is functionable in retrieving user info (name, email, subject, and comments). My only problem is that I need to have the information that the user sends when the click submit to also send an email to the owner with the same info. He wants to get an individual email for each individual who inputs their info and hits submit.

I was trying to derive something from this code to get it to work, but nothing seemed to work:

<?php
$my_result = $_POST['myData'];

$my_result = mail( "sales@longbeachclothing.com", "LBC Site Inquiry: $clientSubject",
"From: ".$clientName . "
Email: ".$clientEmail. "
Subject: ".$clientSubject. "
Message: ".$clientMessage, "From: $clientEmail" );
?>

Here is my current code. There are two files.
The first is called insert.php
<?php
ini_set('display_error',1);
?>
<?php
$connection = mysql_pconnect("localhost","longbeach562","4040314 1") or die('Could not connect: ' . mysql_error());
mysql_select_db("longbeach562", $connection) or die('Could not select database' . mysql_error());
?>
<?php
$_name = $_REQUEST['name'];
$_email = $_REQUEST['email'];
$_subject = $_REQUEST['subject'];
$_comments = $_REQUEST['comments'];

if ($_name != '' && $_subject != '') {
//if ($_name != '') {
$SQL = "INSERT INTO `userInfo` (`name`, `email`, `subject`, `comments`) VALUES ('$_name', '$_email', '$_subject','$_comments');";
mysql_query($SQL) or die('Query failed: ' . mysql_error());
echo("&success=Thank you, your info has been received.");
} else {
echo("&success=Some of your info is missing!");
}
?>

This second on is called select.php:
<?php
ini_set('display_error',1);
?>
<?php
$connection = mysql_pconnect("localhost","longbeach562","4040314 1") or die('Could not connect: ' . mysql_error());
mysql_select_db("longbeach562", $connection) or die('Could not select database' . mysql_error());

// no problems so query the db
$SQL = "SELECT * FROM userInfo;";
$result = mysql_query($SQL) or die('Query failed: ' . mysql_error());
?>
<?php
$output = "<table border=\"1\">\n" .
"<tr>\n" .
"<td>Id</td>\n" .
"<td>Name(s)</td>\n" .
"<td>Email(s)</td>\n" .
"<td>Subject?</td>\n" .
"<td>Comments</td>\n" .
"<td>Date & Time</td>\n" .
"</tr>\n";

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$id = $row[0];
$name = $row[1];
$email = $row[2];
$subject = $row[3];
$comments = $row[4];
$date = $row[5];
$output .= "\t<tr>\n" .
"\t\t<td>$id</td>\n" .
"\t\t<td>$name</td>\n" .
"\t\t<td>$email</td>\n" .
"\t\t<td>$subject</td>\n" .
"\t\t<td>$comments</td>\n" .
"\t\t<td>$date</td>\n" .
"\t</tr>\n";
}

$output .= "</table>\n";
?>
<?php echo($output) ?>
<?php
mysql_free_result($result);
?>
</body>
</html>
Sep 2 '06 #4
Hi,
Thanks for your fast response.
All you code it´s very usefull for me, but i want to explain better my situation.
I include some code:
$mensaje = '
<html>
<head>
<title>Recordatorio de Cumplea&ntilde;os para Agosto</title>
</head>
<body>
<p>&iexcl;Aqu&iacute; est&aacute;n los cumplea&ntilde;os que llegan en Agosto!</p>
<table>
<tr>
<th>Persona</th><th>D&iacute;a</th><th>Mes</th><th>A&ntilde;o</th>
</tr>
<tr>
<td>Juan</td><td>3</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sandra</td><td>17</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
This inserts a 4 colums with 3 lines (Titles ans Data) like this
Persona Día Mes Año
Juan 3 August 1970
Sandra 17 August 1973
I´m looking to put all data into a table with borders, colors, etc and i´m trying to replace the names and dates to variables lik $name, $date, etc.
It´s possible to do that? I´m checked some many documentation (PHP site, web forums but I cannot find and example o any tools to do that.
Thanks a lot .
guillermo
As far as i feel , rather than sending the mail , your actual problem is composing the body variable which has to be emailed.
Suppose $body is the variable storing text to be emailed.

$body = '<table border = 1><tr><td>Sno</td><td>Field 1</td><td>......</td></tr>';
//now for keeping the variables just do this
$body.= '<tr><td><?=$var1?></td><td><?=$var2?></td><tr>';
// Incase this is to be taken from database , just run a while($row=....) and put the above line in between the loops ensuring that var1 and var2 are provided the value you want to send.

After the $body is complete , simply use
mail() with other headers to send it.

If you need more help with mail() function and sending HTML email or MIME-TYPE content , just drop a reply here.

Kind Regards,
Rahul Agrawal
Developer
Web2003 Corporation
www.web2003corp.com
Sep 4 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Stuart Mueller | last post by:
I have an exchange server, that I sometimes use to perform mail shots to clients on our database, these can be upwards of 1000 at a time. As we don't want different clients to see who we are...
3
by: martin smith | last post by:
Here's the scenario. I'm currently using cdosys/asp to send mail to our SMTP server. We use a product called MailFilter to check for SPAM. It doesn't work very well. If MailFilter isn't working...
1
by: Jayakumar | last post by:
HI, I am using System.web.mail class in my application to send mails. I am using SMTP server for the same. I can send mail to the intranet addresses, But when i send mails to Hotmail or other...
7
by: Lau | last post by:
I need to send 1000 emails from an asp.net website. Normally I would use System.Web.Mail.MailMessage() to send thru an SMTP server. But the large amount of emails results in a timeout. My server...
5
by: cashdeskmac | last post by:
I am writing a web application will will be hosted on a few peoples laptops as a local application. It will send e-mails once the user connects to the internet. How can I set up the "Mail.From"...
1
by: Dirk Goossens | last post by:
Hello! I'm sending E-mails to mailadresses in a table, using the code below. How can I send more than one attachment? Access can find the file to be send in this field: MY_EMAILATTACHMENT_FIELD...
8
by: Michel Posseth [MCP] | last post by:
Hi does someone has experience with this ?? i have made a lot of apps in the past that were capable of sending e-mails the server i then talked to was a Linux SMTP server and it worked great ...
1
by: gemma.gill | last post by:
Hi There, I have a button on a form within access that sends a verification e- mail. My problem is that these e-mails are sending from individual user accounts rather than a genieric mailbox. ...
3
by: dskinibbyb | last post by:
Hi Everybody, I am sending mail using the new class in .Net 2.0. Here while sending internal mails it is giving me problem. Carriage return, Line feed and Spaces are lost while sending mails....
2
by: srinivaspnv21 | last post by:
hi every one, plz help me out, i have to send mails from my asp.net page.... I have tried a code where mails are going only to gmail users the code is ... namespace: using System.Web.Mail;...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.