I'm trying to send a form that has both html, php, and mysql queries is this possible? Any documentation?
| SitePoint Sponsor |




I'm trying to send a form that has both html, php, and mysql queries is this possible? Any documentation?


Are you saying someone is typing code into the form and you want that code to appear in the e-mail? There wouldn't be any special handling for that, it's just text like other user input.
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.




No, I'm saying I want stuff to be pulled from the database and sent statically.


PHP Code:mysql_connect("host", "user", "pass");
mysql_select_db("dbname");
$sql = "SELECT name, email FROM user_table";
$sql_result = mysql_query($sql);
while ($row = mysql_fetch_array($sql_result)) {
$body = "Dear " . $row['name'] . ", \n\n";
$body .= "Thank you for being a user of our service!\n\n";
$body .= "Sincerely,\n";
$body .= "Dan";
mail($row['email'], "Just a Thank You!", $body, "From: admin@example.com");
}
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.




In the above how does it know address to send it to and things?


they are taken from the database and assigned $row['email'], assuming you have their email address in the database.....
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!




well i do have, but I need it to email like 4 or 5 different accounts.




also I need to use html to make a table to put the data in?


Have a read through http://uk.php.net/manual/en/function.mail.php, it should answer all your questions![]()
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!

Basically you can build a complete php/mysql driven page and mail the contents once everything is parsed. Just put all the commands within the $body variable.
The below example would mail the results that phpinfo returns to the given e-mail address.
You get the idea. You can do this with both PHP and HTML code and have it sent once everything is parsed.PHP Code:<?php
$body = phpinfo();
mail('you@yourdomain.com','PHP Info from server',$body);
?>
Last edited by Servyces; Jun 13, 2007 at 10:29.
Servyces.com
Where it’s all about you.
Your partner in online solutions.
Visit our website at http://www.servyces.com/




What do you mean put all the commands within the body variable?


17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.

Last edited by Servyces; Jun 13, 2007 at 10:29.
Servyces.com
Where it’s all about you.
Your partner in online solutions.
Visit our website at http://www.servyces.com/




So everything I want to email has to be in there?

Yes or references to earlier executed code. Like:
PHP Code:$query = mysql_query("SELECT name FROM customers WHERE id=3");
while ($row = mysql_fetch_assoc($query)) {
$name = $row['name'];
}
$body = "Dear $name, \r\n";
$body .= "\r\n";
$body .= "Thank you for your inquiry. We will get back to you as soon as possible.";
mail ('me@myinbox.com','Inquiry',$body);
Last edited by Servyces; Jun 13, 2007 at 10:27.
Servyces.com
Where it’s all about you.
Your partner in online solutions.
Visit our website at http://www.servyces.com/
Bookmarks