properly setting email subject line delivered from email form

Posted by DC1 on Stack Overflow See other posts from Stack Overflow or by DC1
Published on 2012-09-21T15:12:56Z Indexed on 2012/09/21 15:37 UTC
Read the original article Hit count: 421

Filed under:
|
|
|

I have a email form for my website but here is the issue: when i receive an email, the subject line in my inbox shows whatever the user inputted as subject in the form. id like to override that so that whenever an email comes in. the subject in the email header is always "an inquiry from your website". In the message body, sure i don't mind their specific subject they entered but when I receive an email, id like consistency in my inbox.

this is the current code:

<?php session_start();
if(isset($_POST['Submit'])) {   if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'xxxxxxxxx';
$fromsubject = 'An inquiry from your website';
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$address = $_POST['address']; 
$city = $_POST['city']; 
$zip = $_POST['zip']; 
$country = $_POST['country']; 
$phone = $_POST['phone']; 
$subject = $_POST['subject']; 
$message = $_POST['message']; 
$headers = "From: $nome <$mail>\r\n";

    $to = $youremail; 
    $mailsubject = 'Message received from'.$fromsubject.' Contact Page';
    $body = $fromsubject.'

    The person that contacted you is  '.$fname.' '.$lname.'
     Address: '.$address.'
    '.$city.', '.$zip.', '.$country.'
     Phone Number: '.$phone.'
     E-mail: '.$mail.'
     Subject: '.$subject.'

     Message: 
     '.$message.'

    |---------END MESSAGE----------|'; 
echo "Thank you for inquiring. We will contact you shortly.<br/>You may return to our <a href='/index.html'>Home Page</a>"; 
                                mail($to, $subject, $body, $headers);
        unset($_SESSION['chapcha_code']);
   } else {
        echo 'Sorry, you have provided an invalid security code';
   }
 } else { 
echo "You must write a message. </br> Please visit our <a href='/contact.html'>Contact Page</a> and try again."; 
}
?> 

© Stack Overflow or respective owner

Related posts about forms

Related posts about email