Jump to content

Recommended Posts

Hi,

 

I am very new to php, and have a contact form on my website (which works!).

 

However, when I receive the email, there is no email subject in the email header. I can see them email content fine, and the senders name, but no email Title.

 

Could somebody possible take a look at the code and see if they spot anything?

 

Thanks in advance,

 

This is my index.html form code

 

	<form id="ajax-contact-form" action="javascript:alert('success!');">
				<fieldset class="info_fieldset">
					<div id="note"></div>
					<div id="fields">
						<label>Name :</label><input class="textbox" type="text" name="name" value="" /><br />
						<label>E-Mail :</label><input class="textbox" type="text" name="email" value="" /><br />
						<label>Message :</label>
						<textarea class="textbox2" name="message" rows="5" cols="25"></textarea>
						<label> </label><input class="button" type="image" src="images/sendNew.png" id="submit" value="Send Message" />	
					</div>
				</fieldset>
	</form>

 

 

This is my contact.php code...

 

<?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']);
$message = stripslashes($_POST['message']);


$error = '';

// Check name

if(!$name)
{
$error .= 'I think you forget to enter your name.<br />';
}

// Check email

if(!$email)
{
$error .= 'I think you forget to enter your e-mail id.<br />';
}

if($email && !ValidateEmail($email))
{
$error .= 'Invalid E-mail id !!!<br />';
}



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">'.$error.'</div>';
}

}
?>

 

Finally this is my config.php code..

 

<?php
// To
define("WEBMASTER_EMAIL", 'xxxxxx@xxxxxx.com');
?>

 

note - I have a contact.php, config.php, functions.php and feedback.php on my webserver, I also have a few javascript files which I think are related to this form - sorry to sound really confusing but I downloaded this form with a template.

 

Like I said, the contact form works fine, just no subject when I get the email.

 

Is it something to do with $headers??

 

thanks again.

 

 

Link to comment
https://forums.phpfreaks.com/topic/263474-php-mail-probably-easy-fix/
Share on other sites

from your scripts, $subject variable is not set.

 

try changing this

contact.php

$mail = mail(WEBMASTER_EMAIL, $subject, $message,
     "From: ".$name." <".$email.">\r\n"
    ."Reply-To: ".$email."\r\n"
    ."X-Mailer: PHP/" . phpversion());

to

$subject = "your subject";
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
     "From: ".$name." <".$email.">\r\n"
    ."Reply-To: ".$email."\r\n"
    ."X-Mailer: PHP/" . phpversion());

That worked!!

 

Really, thank you very much :)

 

I was having real trouble with that and couldn't find an answer anywhere, first post here, and wahey!  :o

 

I am such a noob at php.

 

I know I am pushing it but can I ask one more thing, now that my email sends fine with a subject title, name of sender, and message content.. How do I get all of this information in my email when I open it, eg:

 

 

Subject : Hello

 

From: Joe Bloggs

 

Message: Hi this is my message to you

 

I have all the necessary info, just would like it all in the one place - although not THAT important!

 

Thanks again!!!

Sorry went a bit AWOL...

 

try this...

 

<?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']);
$message = stripslashes($_POST['message']);


$error = '';

// Check name

if(!$name)
{
$error .= 'I think you forget to enter your name.<br />';
}

// Check email

if(!$email)
{
$error .= 'I think you forget to enter your e-mail id.<br />';
}

if($email && !ValidateEmail($email))
{
$error .= 'Invalid E-mail id !!!<br />';
}



if(!$error)
{
$subject = "your subject";
$messageform = stripslashes($_POST['message']);
$message = "Subject: " . $subject . "\n\nFrom: " . $name . "\n\nMessage: " . $messageform;
$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">'.$error.'</div>';
}

}
?>

thanks - this also works a treat!!

 

now when I receive an email I get;

 

Subject: xxxx

 

From: xxxxxx

 

Message: xxxxxx

 

--

 

However I don't get a 'Reply to:' field, is this missing?  :confused:

 

I just noticed that on my actual form, if I don't enter an email address, the form validates and produces the 'I think you forget to enter your e-mail id.' But if I enter an incorrect email (like .bom or .cpm etc) the email form just 'shakes' a bit but produces no error.  :shrug:

 

Could this be linked?

 

thanks :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.