PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pendleton21
Forum Newbie
Posts: 2 Joined: Sun Jul 11, 2010 12:53 pm
Post
by pendleton21 » Sun Jul 11, 2010 1:08 pm
Hello,
I'm sure this probably the easiest question you'll have ever had on this forum but can anyone tell me how I can change the actual email content that is sent out using a contact form I have put on my site? At the moment All I get in the email that is sent out when the form is submitted is the actual message. What I would ideally like in the email is something like this:
Name: John Smith
Email: john@smith.com
Phone: 1234 5678
Message:
Hello, this is my message.
Below is the contact form php code:
Code: Select all
<?php
include 'config.php';
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
include 'functions.php';
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$phone = stripslashes($_POST['phone']);
$subject = 'Website contact form';
$message = stripslashes($_POST['message']);
$error = '';
// Check name
if(!$name)
{
$error .= '<li>Please enter your name.</li>';
}
// Check email
if(!$email)
{
$error .= '<li>Please enter an email address.</li>';
}
if($email && !ValidateEmail($email))
{
$error .= '<li>Please enter a valid e-mail address</li>';
}
// Check message (length)
if(!$message)
{
$error .= "<li>Please enter your message</li>";
}
if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail)
{
echo 'OK';
}
}
else
{
echo '<div class="notification_error"><ul>'.$error.'</ul></div>';
}
}
?>
Any help would be greatly appreciated as I've never done anything with PHP before.
Thanks in advance.
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Sun Jul 11, 2010 2:11 pm
You could set $message so that it includes the information you want. For example:
Code: Select all
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$phone = stripslashes($_POST['phone']);
$subject = 'Website contact form';
$message = "Name: {$name}\nEmail: {$email}\nPhone: {$phone}\nMessage:\n". stripslashes($_POST['message']);
morris520
Forum Commoner
Posts: 60 Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK
Post
by morris520 » Sun Jul 11, 2010 6:04 pm
just be curious for liljester's message
Code: Select all
$message = "Name: {$name}\nEmail: {$email}\nPhone: {$phone}\nMessage:\n". stripslashes($_POST['message']);
What does the bracket mean outside the variable? e,g, {$name}
Could you email me if you wish to answer me?
Many thanks
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Sun Jul 11, 2010 6:48 pm
click the link and scroll down to "Complex (curly) syntax"
http://us.php.net/manual/en/language.types.string.php
basically it tells php that there is a variable of some sort inside the curlies, very helpful for including array names in a string
Code: Select all
$myarray[0]['zero'] = "ABC";
print"abc{$myarray[0]['zero']}123";
// prints: abcABC123
pendleton21
Forum Newbie
Posts: 2 Joined: Sun Jul 11, 2010 12:53 pm
Post
by pendleton21 » Mon Jul 12, 2010 3:00 am
Hey thanks so much liljester, will give that a try when I get home from work.
jessysmithpoo
Forum Newbie
Posts: 1 Joined: Mon Jul 12, 2010 5:08 am
Post
by jessysmithpoo » Mon Jul 12, 2010 7:32 am
cool thanks! exactly what i was looking for.