I have a php page that does a query on a db and spits out a page of records. I would like there to be an email box on that page so they could enter and email and email it. I really have no idea how to do this. Has someone done this that could show me an example or share some code or at least just steer me in the right direction? Thanks you in advance for your help.
Mark
Emailing an html page
Moderator: General Moderators
There is an example at http://www.php.net/manual/en/function.mail.php that shows how to email that has HTML.
All you need to do is change the variables to suit the form that you are passing to this page such as the $subject or $message.
Code: Select all
<?php
/* recipients */
$to = "youremail@example.com"; // who is the email going to
/* subject */
$subject = "Example HTML E-Mail";
/* message */
$message = '
<html>
<head>
<title>Example HTML E-mail</title>
</head>
<body>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
/* and now mail it */
mail($to, $subject, $message, $headers);
?>-
mccommunity
- Forum Commoner
- Posts: 62
- Joined: Mon Oct 07, 2002 8:55 am
Duff Rocks
Thanks a lot duff I really appreciate it.
Mark
Mark
-
niceguyeddie
- Forum Newbie
- Posts: 13
- Joined: Fri Nov 28, 2003 7:12 am
- Location: Westminster, MD
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
-
niceguyeddie
- Forum Newbie
- Posts: 13
- Joined: Fri Nov 28, 2003 7:12 am
- Location: Westminster, MD
This is straight from the readme:microthick wrote:I'm new to classes in PHP. Must I do any thing special to use the class, or just keep the file in the same folder as my php scripts?
Code: Select all
Copy class.phpmailer.php into your php.ini include_path. If you are
using the SMTP mailer then place class.smtp.php in your path as well.
Example
<?php
require("class.phpmailer.php");
$mail = new phpmailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp1.site.com;smtp2.site.com"; // specify main and backup server
$mail->SMTPAuth = true // turn on SMTP authentication
$mail->Username = "jswan" // SMTP username
$mail->Password = "secret" // SMTP password
$mail->From = "from@email.com";
$mail->FromName = "Mailer";
$mail->AddAddress("josh@site.com", "Josh Adams");
$mail->AddAddress("ellen@site.com"); // name is optional
$mail->AddReplyTo("info@site.com", "Information");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <br/><br/>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>Code: Select all
include 'path/to/class.phpmailer.php';