Log in

View Full Version : Customize subject line in received emails



BlueCat
11-18-2010, 11:54 AM
Hello,
I want to change the default subject line I receive from my contact form

from:
[ No Subject ]
to:
You have an inquiry

Can that be done in my php form page? Do I also have to have it the html page?

Thanks,
Mary Jo

Nile
11-18-2010, 01:10 PM
The subject is an option when using the mail() function:


bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

djr33
11-18-2010, 02:17 PM
But of course if you are using some other method of sending the email, the subject may need to be set another way. We'd need to see your code to help with that.

BlueCat
11-18-2010, 09:58 PM
Thanks for your reply. Here is the code.

My wish is to have the subject filled in with the text "You have an inquiry from the website".


<?php

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$user_comments = $_POST['comments'];

$myemail = "msajdowitz@yahoo.com";

$comments = "
Your contact form has been submitted by:

Name: $name
Phone: $phone
Email: $email
Comments:
=======================================
$user_comments
=======================================
";

$extraheaders = "From: $email\n\r Email sent from: $email\n\r";

if (! mail($myemail, $subject, $comments, $extraheaders))
echo "Mail did not send for some reason.";

header("Location: thankYou.html");

?>
________________________________________________________
Here is the html of the form if you need it.

<div id="cForm">
<form id="form1" name="form1" method="post" action="contactInfo.php">
<span id="sprytextfield1">
<label for="name">Your Name: <span class="astric">*</span></label>
<input name="name" type="text" id="name" size="30" />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span>
<p><span id="sprytextfield3">
<label for="phone">Your Phone: <span class="astric">*</span></label>
<input name="phone" type="text" id="phone" size="30" />
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
</p>
<p>
<label for="email">Your Email: &nbsp;&nbsp;</label>
<input name="email" type="text" id="email" size="30" />
</p>
<p>Comments or Questions:</p>
<p>
<label for="comments"></label>
<textarea name="comments" id="comments" cols="45" rows="5"></textarea>
</p>
<p>
<label for="button"></label>
<input type="submit" name="button" id="button" value="Submit" />
</p>
<p class="required"><span class="astric">*</span> indicates required</p>
</form>
</div>

Thanks for your help

Schmoopy
11-18-2010, 10:05 PM
At the moment the $subject variable is not being set anywhere in your script. Change the following part of your script:



$subject = 'You have an inquiry from the website';

$extraheaders = "From: $email\n\r Email sent from: $email\n\r";

if (! mail($myemail, $subject, $comments, $extraheaders))
echo "Mail did not send for some reason.";

BlueCat
11-18-2010, 10:34 PM
Wow! Thanks. That worked