Question

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."; 
}
?> 
Was it helpful?

Solution

It appears as though you have set a variable called $subject elsewhere.

$subject = $_POST['subject']; 

and then use that same variable to send your mail.

mail($to, $subject, $body, $headers);

Try creating another variable for the second use or changing it prior to suit your needs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top