FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Mail - Always Junked?





ninjakannon
I often use the php 'mail' function to send emails; the problem is that the emails are always sent to the junk folder. Now, I've received emails from phpbb forums (obviously sent from php files) which aren't ever junked - I don't have to add the email address to my allow list. However, some emails from phpbb forums are junked.

So how do I ensure that emails sent from my php files are not junked either?
sonam
Open and email on gmail and send all post from phpbb on this account. Select there how this post is not spam and then forward to right mail adress. Shocked

Sonam
ninjakannon
sonam wrote:
Open and email on gmail and send all post from phpbb on this account. Select there how this post is not spam and then forward to right mail adress.

I think you got the wrong message there, I don't mind the emails being junked when I sign up to a forum as I just check my junk mail. I was only using signing up to a forum as an example of when some emails are junked and some are not.

What I want to know, is why some emails from php files are not sent to the junk folder and how I can stop emails from my php files being junked too.
sonam
Oh sorry for my mistake. I didn't understand your question right.

Quote:
What I want to know, is why some emails from php files are not sent to the junk folder and how I can stop emails from my php files being junked too.


Maybe is something in mail body what spam filter treat like spam. Did you try to send plain mail form your site (just few words) using sent mail php. If plain mail also going in junk folder than is something wrong in mail header.

Sonam
ninjakannon
sonam wrote:
Oh sorry for my mistake. I didn't understand your question right.

No problem, no worries. Smile

sonam wrote:
Maybe is something in mail body what spam filter treat like spam. Did you try to send plain mail form your site (just few words) using sent mail php. If plain mail also going in junk folder than is something wrong in mail header.

Yeah, my the emails are junked even when I send plain emails. If, as you say, it's the headers which are wrong - which headers should I use?

Currently I'm only using this one header:
Code:
$headers = 'From: email@address.com';
SlowWalkere
It could be that the e-mail address you're sending isn't realistic. You might want to change it to "admin@ninja.frihost.com" or whatever your domain is. I'm not sure how sophisticated the filter is, tho, and whether or not it would look at that.

Also, there was a problem a while back with Frihost's server being blacklisted by many ISPs. Someone had apparently been sending out spam and they were shut down, but not before people got annoyed and reported the server's address. Bondings said he was working on fixing it, but I don't know what actually happened. Maybe the server is still blacklisted, and the filter uses that to sort out spam?

Just some thoughts,
- Walkere
ninjakannon
SlowWalkere wrote:
It could be that the e-mail address you're sending isn't realistic.

The address I'm using is definitely realistic, it is similar to the one you suggested and I've had problems with others like it in the past.

Perhaps your latter suggestion is correct - I'm sending to a hotmail account, I don' know whether there's a way to find out which servers are blacklisted on there.

Thanks for your thoughts. Smile
qscomputing
Mail generated from the PHP mail() function does have a habit of being treated as spam. I can't remember the causes offhand, but there is a solution. Try looking in the PHP manual (http://www.php.net/function.mail), but always remember that Google is your friend. Smile

You could of course open a pipe to sendmail and send your email that way - that seems to work fine for me, although I use perl rather than PHP.
ninjakannon
Thanks for that, qscomputing. One problem... I still can't find anything! I've been hunting around on Google and found quite a few other forums where people have posted the same problem. One guy fixed his problem by getting added to the whitelist of the various email companies (AOL, Yahoo! etc - Gmail was okay already though).

You mention opening a pipe to sendmail, how do you do this?

I would be very obliged if you would find the causes of this (if it's not merely that you need to be on the whitelists or get removed from blacklists); so long as it doesn't take up too much of your time.
sonam
When I am talking about header I think on mail header:

Code:
$recipient = "yourmail@domain.com;  // your email
$email    = $_POST['email'];   // user email
$subject  = $_POST['subject'];  // user subject
$msg      = $_POST[msg];  // user message

mail($recipient,$subject,$msg,"From: $email\r\n"."Reply-To: $email\r\n");  // mail header


Are your header contain all needed things? If is not maybe this cause problem.

Sonam
ninjakannon
Sonam wrote:
Are your header contain all needed things?

I have only used the former header from the two you gave. Do you really think that adding a 'Reply-To:' header will really stop the mail from being junked? Anyway, there won't be anyone to reply to as the email script that I'm currently working on sends me information that users have filled in on the contact form on my website.
sonam
Quote:
Do you really think that adding a 'Reply-To:' header will really stop the mail from being junked?


I don't know. Sometimes, for testing, I am using klfajkjla@jklaf.com and this mails also comming in my inbox. BTW many automated mails have subject "This is automated mail. Please, do not reply on this mail." what means they sent 'Reply-To:' header.

Sonam
qscomputing
ninjakannon wrote:
You mention opening a pipe to sendmail, how do you do this?

Euh, now my PHP knowledge lets me down. I use the following code in Perl:

Code:
my $mailer = '/usr/sbin/sendmail -oi -t -oem';
my $from = '"QSComputing" <postmaster@qscomputing.net>';
sub _mail_start {
   my ($sender, @recipients) = @_;
   
   my $command = $mailer;
   $command .= qq{ -f "$sender"};
   
   my $result;
   eval {
      local $SIG{__DIE__};
      $result = open SENDMAIL, "| $command";
   };
   if ($@) {
      die $@ unless $@ =~ /\$ENV{PATH}/;
      delete $ENV{PATH};
      $result = open SENDMAIL, "| $command";
   }
   
   die "Can't open mailprog [$command]\n" unless $result;
}

sub _mail_end {
   close SENDMAIL or die "close sendmail pipe failed, mailer=[$mailer]";
}

#MAIN SEND MAIL FUNCTION

sub send_mail {
   my ($to, $subject, $body) = @_;
   
   _mail_start($to);
   
   my $addr = $main::cgi->remote_addr();
   $addr =~ /^([\d\.]+)$/ or die "bad remote addr [$addr]";
   $addr = $1;
   print SENDMAIL <<ENDOFMAIL;
X-HTTP-Client: [$addr]
X-Generated-By: QSComputing.net
To: $to
Reply-to: $from
From: $from
Subject: $subject

$body
ENDOFMAIL
   _mail_end();
}


Note that this is Perl, not PHP, but translation shouldn't be that difficult. A quick glance at the PHP manual suggests that the popen() function can be used to open a pipe, and then you can write to it just like you write to a file:

Code:
<?php
$handle = popen('/usr/sbin/sendmail -oi -t -oem', 'w');
fwrite($handle, 'stuff I want to write');
pclose($handle);
?>


Obviously you'll need to understand Perl to make full sense of what I wrote, but a lot of it is security code that you would implement differently in PHP. This bit is the important bit:

Code:
print SENDMAIL <<ENDOFMAIL;
X-HTTP-Client: [$addr]
X-Generated-By: QSComputing.net
To: $to
Reply-to: $from
From: $from
Subject: $subject

$body
ENDOFMAIL


You can just replace all of that with a fwrite for each line, making sure that you substitute in the appropriate values. $addr is the remote user's IP address; the rest is self-explanatory. The first and last lines are like quote characters that enclose the entire section.

If you have any questions, please don't hesitate to ask.

HTH,
- QS.
ninjakannon
From what you've given me there, and php.net's page on popen() I scrambled up:

Code:

<?php

$to = 'my@email.com';
$subject = 'My Subject';
$from = 'madeup@domain.net';
$message = "Hi,<br>You got my message!";

$handle = popen("/usr/sbin/sendmail  -oi -t -oem", "w");
fputs($handle, "Content-type: text/html\r\n");
fputs($handle, "To: $to\r\n");
fputs($handle, "From: Test Name <" . $from . ">\r\n");
fputs($handle, "Subject: $subject\r\n");
fputs($handle, "X-Mailer: PHP4\r\n\r\n");
fputs($handle, $message);

if ($handle) {
      echo 'Sent';
} else {
      echo 'Error';
}

pclose($handle);
?>

I get the email, but it's still junked.

I also found that, if you don't say who it's from the email is sent from ninjakannon[at]host.frih.net - which is interesting, but off-topic a bit. Razz

So what have I done wrong?
qscomputing
OK, in that case I don't know. ISTR reading something about this specific to phpBB and the solution could be generalised, but I don't remember where I found it. Try asking at the phpBB.com forums.
ninjakannon
Well thanks for the help anyway, gscomputing. I will ask on the phpbb.com forums - I just hope they can help me, or that someone else here on FriHost will know how to fix this.
Gundamxxg
ninjakannon,

for the mail to work you cannot have headers set with the php doc.

your php script needs to look similar to

Code:

<?
$to = $_POST['email']; // where 'email' is the form field name and carries who the mail is going to be sent to.
$subject  = $_POST['subject'];  // where 'subject' is the form field name and carries the subject of the email
$message = $_POST['message']; // where message is the form field name that carries the message that is being sent

mail($to, $subject, $message);

?>



that is all you need and your mails will be sent directly to the inbox rather than the junk box. that is the current script that i use and it works fine.
ninjakannon
Which email provider (is that the correct term?) are you sending your emails to? I just used your exact script to a Windows Live Mail address and the message was still junked. However, Microsoft Outlook receives emails from all the methods I've tried. The problem is that my default email address is on Windows Live Mail and so are millions of other people's accounts so I need a script which sends an email which isn't junked.

Thanks for the help.
Gundamxxg
My script I know works for google, yahoo, msn and AOL. I havent tried anything with windows live mail. Ill have to check that out to see what kind of coding I will have to change in order for mail functions to work.


Thanks for that info =)
ninjakannon
Gundamxxg wrote:
My script I know works for google, yahoo, msn and AOL. I havent tried anything with windows live mail. Ill have to check that out to see what kind of coding I will have to change in order for mail functions to work.

If you add some headers does the email still get through to those companies?

I think this is just a case of Windows Live Mail having an over-sensitive spam filter, as I can't seem to get any messages from a php file through, but other email providers receive the mail with no problems.
Gundamxxg
ninjakannon wrote:
Gundamxxg wrote:
My script I know works for google, yahoo, msn and AOL. I havent tried anything with windows live mail. Ill have to check that out to see what kind of coding I will have to change in order for mail functions to work.

If you add some headers does the email still get through to those companies?

I think this is just a case of Windows Live Mail having an over-sensitive spam filter, as I can't seem to get any messages from a php file through, but other email providers receive the mail with no problems.


If I add headers to the mail function I have had 1 of 2 things happen. One posibility is that the mail will not send (can't remember exactly why that happens but I know it is something that has changed since the release of php5 and something else). The other thing that happens is if the mail does get sent it will be junked. The email filters see that specified headers as spam and thus deal with it appropriately. I'm still looking for a way to get around that because I kinda liked having my headers.
ninjakannon
Gundamxxg wrote:
If I add headers to the mail function I have had 1 of 2 things happen. One posibility is that the mail will not send (can't remember exactly why that happens but I know it is something that has changed since the release of php5 and something else). The other thing that happens is if the mail does get sent it will be junked. The email filters see that specified headers as spam and thus deal with it appropriately. I'm still looking for a way to get around that because I kinda liked having my headers.

That's odd, I can't think of a logical reason why you would want to junk (or simply not receive) emails with specified headers.

When (or if) you find out how to send the message successfully with headers (or send successfully to Windows Live Mail), I would be really grateful if you would PM me because I'm stumped here. My knowledge of php isn't that great so I doubt I'll figure something out on my own.
Related topics
PHP Mail Function
php mail and BCC
PHP mail function ?
Does FriHost support php mail?
Php mail function
Envoi de mail via PHP sur frihost
Can You Get HTML in Your PHP Mail Script?
PHP Mail
PHP mail() Function
SMTP, sendmail e PHP mail function
Php mail
Webmail, not PHP Mail, has never worked for me...
php mail(); problem... half fixed?
PHP mail() function...
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.