PDA

View Full Version : Please help with this email code...


F360
07-01-2006, 11:51 PM
Hey guys!
Im new to php and trying to add a little modification to this code. The code currently sends an email to someone via a website. The subject,from email,to email and message are all entered in forms.
What I want to add is a bit of code that adds to the email message "This is a fake email etc etc" before the actual message. I hope that makes sense :thumbsup:

<?php
if(@isset($_POST['submit'])) {
// require fields...look at the hidden field to change what's required
$required_fields = explode(",", $_POST['required']);

$error = 0;

foreach($required_fields as $fieldname) {
if ($_POST[$fieldname] == "") {
$error++;
}
}


if ($error == 0) {
if (strstr($_POST['to'], "@") and strstr($_POST['to'], ".")) {
if (strstr($_POST['from'], "@") and strstr($_POST['from'], ".")) {
// headers to be included in email
$headers .= "MIME-Version: 1.0\n";
// html header (delete the following row if you do not want html to show)
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
// from header
$headers .= "From: $_POST[name] <$_POST[from]>";
// mail function
mail("$_POST[to]" , "$_POST[subject]", $_POST[message], $headers);

// success message
// if you receive a php error, make sure your server is set up to send email
print "<b><font size=2>Your email has been sent to $_POST[to] from $_POST[from]</font></b>";
exit;

}
} else {
$errormessage = "<b><font color=red>The email address you entered does not appear to be valid.</font><br></b>";
}


} else {
$errormessage = "<b><font color=red>You have left some required fields in the form blank. Please fill in the form completely.</font><br></b>";
}
}
?>

Thanks for any helps guys. Also, sorry I came here to ask a question before actually contributing. Hopefully I can do that in the future :thumbsup:

Later!

F360
07-02-2006, 01:44 AM
Nevermind guys, it's working now :)

Fumigator
07-02-2006, 01:49 AM
You simply need to append whatever string you want to include in the email to the string that is currently used in the subject.

So make a string (use "\n" to put a newline in there):


//string to add to email subject (with two newlines)
$myMessage = "This is such a fake email.\n\n"


And then append this new string to the existing string, using the period character ".":

mail("$_POST[to]" , "$_POST[subject]", $myMessage.$_POST[message], $headers);

F360
07-02-2006, 05:32 AM
Thanks...that works better now :thumbsup: