views:

41

answers:

1

I need to modify this PHP mail form to have the email subject include "New message from photography site" before the subject supplied by the visitor who submits the form. I don't know PHP and tried a few things, but always got a T_STRING error when trying to add it into the line where the $subject variable is created.

<?php
/*
Credits: Bit Repository
URL: http://www.bitrepository.com/web-programming/ajax/tableless-form-using-jquery.html
*/

include 'config.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if($post)
{
include 'functions.php';

$name = stripslashes($_POST['name']);  
$email = $_POST['email'];  
$subject = stripslashes($_POST['subject']);  
$message = stripslashes($_POST['message']);

$error = '';

// Check name

if(!$name)
{
$error .= 'Please enter your name.';
}

// Check email

if(!$email)
{
$error .= 'Please enter an e-mail address.';
}

if($email && !ValidateEmail($email))
{
$error .= 'Please enter a valid e-mail address.';
}

// Check message (length)

if(!$message || strlen($message) < 15)
{
$error .= "Please enter your message. It should have at least 15 characters.";
}

if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message, $email);

if($mail)
{
echo 'OK';
}

}
else
{
echo '<div class="notification_error">'.$error.'</div>';
}

}
?>
+4  A: 

Change this line:

$name = stripslashes($_POST['name']);
$email = $_POST['email'];
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);

to:

$name = stripslashes($_POST['name']);
$email = $_POST['email'];
$subject = "New message from photography site: " . stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);
silent
@silent Thank you. I'm experienced with formatting languages like HTML/CSS, but am just starting to learn programming a bit.Based on the comments from other people, what would make my post more appropriate for StackOverflow?I'm thinking I probably should have just posted the one line of code that needed an addition. Otherwise, is there a different website where I should post these kinds of simple PHP questions?Thank you.