Jump to content

mail() sometimes sends with empty subject/headers...


mameha

Recommended Posts

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?

Link to comment
Share on other sites

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?).

Link to comment
Share on other sites

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: server@barnyard.com\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";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.