mameha Posted February 13, 2007 Share Posted February 13, 2007 I'm using the simple mail() function. mail($To, $Subject, $Message, $headers); 95% of the time it works fine, but twice now it has sent out the mail using the correct 'to' and 'message' fields but the 'subject' and 'headers' were empty. I declare the 'subject' immediately before sending the mail with this line: $Subject = "Quote (".$thecountry."/".$lang.") ".strip_tags($_POST['company_name']); The headers are also set in this way, then the mail is sent. I can't think of anything that would cause the values to disappear such as using sessions etc. Whats going on here? Quote Link to comment https://forums.phpfreaks.com/topic/38247-mail-sometimes-sends-with-empty-subjectheaders/ Share on other sites More sharing options...
redarrow Posted February 13, 2007 Share Posted February 13, 2007 try this only ok. i think the $_POST is doing it. <?php //post varable as a one statement not included in the subject line. $company_name=strip_tags($_POST['company_name']); $Subject = "Quote (".$thecountry."/".$lang."/".$company_name."); ?> Quote Link to comment https://forums.phpfreaks.com/topic/38247-mail-sometimes-sends-with-empty-subjectheaders/#findComment-183208 Share on other sites More sharing options...
Jessica Posted February 13, 2007 Share Posted February 13, 2007 Is it possible people are using it and not filling in those fields? Quote Link to comment https://forums.phpfreaks.com/topic/38247-mail-sometimes-sends-with-empty-subjectheaders/#findComment-183228 Share on other sites More sharing options...
mameha Posted February 13, 2007 Author Share Posted February 13, 2007 I will try to remove the striptags from the mail as advised. But I have no way to test this, I tried recreating the error using the original data (it gets stored int he DB ok before pulling out and mailing) but I cant recreate it. So I just have to wait and see. Is it possible people are using it and not filling in those fields? In this case they did fill in the fields. Even if they didn't, it should still make a subject of "Quote(/)" or similar. The problem I had was the subject was NULL. Hopefully the advice above will solve it (although wouldnt that be a bug in PHP / mail function?). Quote Link to comment https://forums.phpfreaks.com/topic/38247-mail-sometimes-sends-with-empty-subjectheaders/#findComment-183234 Share on other sites More sharing options...
Jessica Posted February 13, 2007 Share Posted February 13, 2007 I dunno, with mail it could be a billion things :/ Best of luck. Quote Link to comment https://forums.phpfreaks.com/topic/38247-mail-sometimes-sends-with-empty-subjectheaders/#findComment-183237 Share on other sites More sharing options...
mameha Posted February 13, 2007 Author Share Posted February 13, 2007 Yeah im starting to think its a problem with my local server which has all kinds of anti spam and stuff on it and cannot handle chinese etc. im gonna find out if the real recipient gets this blank subject problem or not. Quote Link to comment https://forums.phpfreaks.com/topic/38247-mail-sometimes-sends-with-empty-subjectheaders/#findComment-183240 Share on other sites More sharing options...
redarrow Posted February 13, 2007 Share Posted February 13, 2007 Ok here you go fully tested, And found all the faults for you, Be very carefull useing any mail function and the use of the mail statements. good luck. <?php $to ='the mail address@your use'; $thecountry="hi there"; $lang="i am redarrow"; $company_name="i love php"; $company_name=strip_tags($company_name); $subject = "Quote($thecountry/$lang/$company_name)"; $message = '<b>yo</b>, whassup?'; $headers = "From: [email protected]\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; // Send if(mail($to, $subject, $message, $headers)){ echo" your mail was sent to $to"; }else{ echo "sorry the mail was not sent to $to"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/38247-mail-sometimes-sends-with-empty-subjectheaders/#findComment-183296 Share on other sites More sharing options...
zq29 Posted February 13, 2007 Share Posted February 13, 2007 Did you actually read this topic properly redarrow? Quote Link to comment https://forums.phpfreaks.com/topic/38247-mail-sometimes-sends-with-empty-subjectheaders/#findComment-183436 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.