473,652 Members | 3,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending mails with PHP with tables

2 New Member
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 3065
Niheel
2,456 Recognized Expert Moderator Top Contributor
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
gsalgado
2 New Member
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>Recordat orio de Cumplea&ntilde; os para Agosto</title>
</head>
<body>
<p>&iexcl;Aqu&i acute; 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
ArtDerailed
2 New Member
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@longbeac hclothing.com", "LBC Site Inquiry: $clientSubject" ,
"From: ".$clientNa me . "
Email: ".$clientEm ail. "
Subject: ".$clientSubjec t. "
Message: ".$clientMessag e, "From: $clientEmail" );
?>

Here is my current code. There are two files.
The first is called insert.php
<?php
ini_set('displa y_error',1);
?>
<?php
$connection = mysql_pconnect( "localhost","lo ngbeach562","40 403141") 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($SQ L) 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('displa y_error',1);
?>
<?php
$connection = mysql_pconnect( "localhost","lo ngbeach562","40 403141") 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($SQ L) 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>Subjec t?</td>\n" .
"<td>Commen ts</td>\n" .
"<td>Date & Time</td>\n" .
"</tr>\n";

while ($row = mysql_fetch_arr ay($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>$i d</td>\n" .
"\t\t<td>$n ame</td>\n" .
"\t\t<td>$email </td>\n" .
"\t\t<td>$subje ct</td>\n" .
"\t\t<td>$comme nts</td>\n" .
"\t\t<td>$d ate</td>\n" .
"\t</tr>\n";
}

$output .= "</table>\n";
?>
<?php echo($output) ?>
<?php
mysql_free_resu lt($result);
?>
</body>
</html>
Sep 2 '06 #4
rkagrawal
13 New Member
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>Recordat orio de Cumplea&ntilde; os para Agosto</title>
</head>
<body>
<p>&iexcl;Aqu&i acute; 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><?=$va r1?></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
4967
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 working with we put these mailshots in the bcc field of the mails. This can sometimes cause a problem as we are getting alot of mails bounced back. I would like to write a script to have these emails sent out individually using the to: field of the...
3
6261
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 cdosys also has problems and emails don't get sent. As these email are confirmations for customer's bookings this means lots of customers calling to see where their confirmation emails have gone. The root of the problem is MailFilter but that here...
1
1760
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 domains the mails are not sent. What should i do for the sending mails to hotmail and other accounts. (But if i have send mails to hotmail from my acount then i can send mails. ) Kindly reply for my problems.
7
3512
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 administrator told me to write the emails to the “pickup directory†instead. I know that JMail can do this in ASP, but how do you do this in asp.net? -- --------------------
5
1522
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" field if I don't know the address of the user's laptop? I have managed to get it working on my own machine, but setting the "From" filed to "Localhost" doesn't seem to work. Any suggestions?
1
1633
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 I have also a field with the name MY_EMAILATTACHMENT_FIELD2 Combining the field names with an &-sign doesn't work, even when I put a ; in between. Thanks for a helping hand!
8
2842
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 Now i work in a company with a MS exchange server and would like to send some e-mails however i can`t get it to work at all error is : ( translated form the dutch language )
1
2151
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. Is there a way to do this? We are using MS Outlook each user has an account set up that gives them a personal mailbox and access to another mailbox "helpdesk". I
3
2377
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. I am using msg.BodyEncoding = System.Text.UTF8Encoding.UTF8 to encode the body. But same code and same mail is going fine , when sent to external mails (Like gmail, yahoo, etc.) Please can anyone help me in solving my problem. I even tried...
2
1382
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; protected void btnSend_Click(object sender, EventArgs e) {
0
8703
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.