stcolumb Posted June 1, 2012 Share Posted June 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263474-php-mail-probably-easy-fix/ Share on other sites More sharing options...
jason310771 Posted June 1, 2012 Share Posted June 1, 2012 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()); Quote Link to comment https://forums.phpfreaks.com/topic/263474-php-mail-probably-easy-fix/#findComment-1350256 Share on other sites More sharing options...
stcolumb Posted June 1, 2012 Author Share Posted June 1, 2012 thanks - i'll give this a go now and let you know! Quote Link to comment https://forums.phpfreaks.com/topic/263474-php-mail-probably-easy-fix/#findComment-1350265 Share on other sites More sharing options...
stcolumb Posted June 1, 2012 Author Share Posted June 1, 2012 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! 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/263474-php-mail-probably-easy-fix/#findComment-1350326 Share on other sites More sharing options...
downah Posted June 1, 2012 Share Posted June 1, 2012 <?php $messageform = stripslashes($_POST['message']); $message = "Subject: " . $subject . "\n\nFrom: " . $name . "\n\nMessage: " . $messageform; ?> Quote Link to comment https://forums.phpfreaks.com/topic/263474-php-mail-probably-easy-fix/#findComment-1350329 Share on other sites More sharing options...
stcolumb Posted June 1, 2012 Author Share Posted June 1, 2012 thanks downah, but where do I put this code exactly? Quote Link to comment https://forums.phpfreaks.com/topic/263474-php-mail-probably-easy-fix/#findComment-1350336 Share on other sites More sharing options...
jason310771 Posted June 3, 2012 Share Posted June 3, 2012 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>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/263474-php-mail-probably-easy-fix/#findComment-1350872 Share on other sites More sharing options...
stcolumb Posted June 6, 2012 Author Share Posted June 6, 2012 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? 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. Could this be linked? thanks Quote Link to comment https://forums.phpfreaks.com/topic/263474-php-mail-probably-easy-fix/#findComment-1351649 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.