James <Ja***@NotHere.com> wrote in message
news:<cd********************************@4ax.com>. ..
How can I take my form data and send it as an email using my SMTP server
located @ my ISP using PHP ?
my form has several fields:
TO: this is a drop down list
FROM: this is a drop down list
SUBJECT: Free Type
MESSAGE: Free Type
CC: Check Box
what I need to do is send the email TO the user selected, FROM the user
selected, with the Subject and Message, If ticked CC then copied to the
FROM user !
Any Ideas ?
Actually, two. :)
1. If your ISP allows you to use the mail() function and has it
properly configured:
if ($_POST) {
$to = $_POST['TO'];
$from = $_POST['FROM'];
$subject = $_POST['SUBJECT'];
$message = $_POST['MESSAGE'];
} else {
die ('What the heck am I supposed to mail?');
}
$headers = 'From: ' . $from . "\r\n";
if ($_POST['CC']) {
$headers .= 'Cc: ' . $from . "\r\n";
}
mail ($to, $subject, $message, $headers);
2. If not, get yourself a copy of phpMailer (
http://phpmailer.sf.net/)
and send your message via an external SMTP server:
require ('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.mysite.com';
$mail->SMTPAuth = true; // These three lines are necessary
$mail->Username = 'me'; // only if your SMTP server
$mail->Password = 'my_password'; // requires authentication
$mail->From = $_POST['FROM'];
if ($_POST['CC']) {
$mail->AddCC($_POST['FROM']);
}
$mail->Subject = $_POST['SUBJECT'];
$mail->IsHTML(false);
$mail->Body = $_POST['MESSAGE'];
$mail->Send();
Cheers,
NC