Jump to content


Photo

why would a form only work for some emails?


  • Please log in to reply
10 replies to this topic

#1 Jus

Jus
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 June 2006 - 09:02 AM

Hi,

I'm working on a form script, and it works pretty well. Sends HTML emails to addys I specify.

The only problem is, the script only works for some emails. Gmail and hotmail thus far. When I try to use the script on my personal emails, it never even gets to the server. I'm wondering if it's something wrong with my headers, or the "from" field. The forms are coming from an empty sender, so maybe the server assumes it's spam?

But that doesn't explain why the "webmaster" copy of the form comes through fine; it has an empty from field as well. I'm completely stumped.

I don't even know what code to post, since I don't know the cause of this problem. I ran a search here and saw this thread:
[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95748&hl=\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...topic=95748&hl=[/a]

but he has a different code than I do.

Any suggestions?

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 June 2006 - 10:01 AM

post the code that builds your email, up to and including your mail() function call
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 Jus

Jus
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 June 2006 - 10:04 AM

thanks for the quick response...

    # Send email here ------------------------------------------------------------------------------

    if (file_exists("$up_dir/what/$what/attach.txt")){
        # Send mail Attachment
        $fh = fopen ("$up_dir/what/$what/attach.txt", "r");
        while (!feof ($fh)) {
            $check_attach_txt .= fgets($fh, 4096);
        }
        fclose ($fh);

        $get_info = preg_split ("/\|/", $check_attach_txt);
        $num_file_att = $get_info [0];
        $max_upload_size = $get_info [1];
        $keep_file = $get_info [2];
        $not_allow_type = $get_info [3];
        $adv = $get_info [4];
        $adv_error = $get_info [5];

        $fh = fopen ("$up_dir/what/$what/send_to.txt", "r");
        while (!feof ($fh)) {
            $webmaster_mail_list .= fgets($fh, 4096);
        }
        fclose ($fh);

        $array_webmaster_email = explode("\n", $webmaster_mail_list);
        $array_for_att = explode("\n", $for_att);

        foreach ($array_webmaster_email as $val) {
            if ($val != ""){
                if ($email_html == 1 || $email_html == 2) {
                    # HTML FORMAT
                    Send_Mail_Att($array_user_email[0],$val,$subject. " (For webmaster)","HTML",$array_for_att,$email_webmaster);                
                }
                else{
                    # TEXT FORMAT
                    Send_Mail_Att($array_user_email[0],$val,$subject. " (For webmaster)","TEXT",$array_for_att,$email_webmaster);
                }
            }
        }
        
        # Check Keep file YES NO
        if ($keep_file == "no"){ # File Attachment will be deleted
            foreach ($array_for_att as $value){
                if ($value != ""){
                    unlink ("$value");
                }
            }
        }

    }
    else{

        # Send email to Webmaster ((normal - no attachment))

        $fh = fopen ("$up_dir/what/$what/send_to.txt", "r");
        while (!feof ($fh)) {
            $webmaster_mail_list .= fgets($fh, 4096);
        }
        fclose ($fh);

        $array_webmaster_email = explode("\n", $webmaster_mail_list);

        foreach ($array_webmaster_email as $val) {
            if ($val != ""){
                if ($email_html == 1 || $email_html == 2) {
                mail($val, $subject. " (For webmaster)", $email_webmaster, "From: $array_user_email[0]\r\nContent-Type: text/html\r\nX-mailer: PHP/");
                }
                else{
                mail($val, $subject. " (For webmaster)", $email_webmaster, "From: $array_user_email[0]\r\nContent-Type: text/plain\r\nX-mailer: PHP/" );
                }
            }
        }

    } # end if attch.txt

    # Send email to User (normal - no attachment)

    foreach ($array_user_email as $val) {
        if ($val != ""){
            if ($email_html2 == 1 || $email_html2 == 2) {
            mail($val, $subject, $email_user, "From: $array_webmaster_email[0]\r\nContent-Type: text/html\r\nX-mailer: PHP/");
            }
            else{
            mail($val, $subject, $email_user, "From: $array_webmaster_email[0]\r\nContent-Type: text/plain\r\nX-mailer: PHP/" );
            }
        }
    }

exit;
} # End if ($ch_thank != "1") {
} # End function step_2()

# ----------------------------------------------------------------

function Send_Mail_Att($From,$To,$Subject,$Format,$File_Att,$Email_Mess){
global $upload_dir;

$OB="----=_OuterBoundary_000";
$IB="----=_InnerBoundery_001";

$headers ="MIME-Version: 1.0\r\n"; 
$headers.="From: ".$From."\n"; 
$headers.="To: ".$To."\n"; 
$headers.="Reply-To: ".$From."\n"; 
$headers.="X-Mailer: PHP Mailer\n"; 
$headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n";

$Msg ="This is a multi-part message in MIME format.\n";
$Msg.="\n--".$OB."\n";
$Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";

if ($Format == "TEXT"){
    $Msg.="\n--".$IB."\n";
    $Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
    $Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
    $Msg.=$Email_Mess."\n\n";
}
else{
    $Msg.="\n--".$IB."\n";
    $Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
    $Msg.="Content-Transfer-Encoding: base64\n\n";
    $Msg.=chunk_split(base64_encode($Email_Mess))."\n\n";
}

$Msg.="\n--".$IB."--\n";

if($File_Att){
     foreach($File_Att as $File_Att_val){
         if ($File_Att_val != ""){
            $patharray = explode ("/", $File_Att_val); 
            $FileName=$patharray[count($patharray)-1];
            $Msg.= "\n--".$OB."\n";
            $Msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n";
            $Msg.="Content-Transfer-Encoding: base64\n";
            $Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n";

            $fd=fopen ($File_Att_val, "r");
            $FileContent=fread($fd,filesize($File_Att_val));
            fclose ($fd);
            $FileContent=chunk_split(base64_encode($FileContent));
            $Msg.=$FileContent;
            $Msg.="\n\n";
         }
     }
}

$Msg.="\n--".$OB."--\n";
mail($To,$Subject,$Msg,$headers); 

}


#4 d_barszczak

d_barszczak
  • Members
  • PipPipPip
  • Advanced Member
  • 188 posts
  • LocationBradford - UK

Posted 26 June 2006 - 10:08 AM

I have used the mail() function in a few of my scripts but the main falw is that anti-spammers tend to catch the emails as the webservers ip address tends not to resove back to the From: headers mailserver.

ie.

www.scripts2go.co.uk 10.0.0.1 - is the webserver.

sales@scripts2go.co.uk 10.0.0.2 - is the mailserver.

and when the senders ip address is resolved to an IP which is differant from the senders From Header the spammer eats it.

When all else fails - Try reading the manual.

Integrated IT Systems Ltd


#5 Jus

Jus
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 June 2006 - 10:12 AM

Interesting. Were you able to find a way around it?

#6 d_barszczak

d_barszczak
  • Members
  • PipPipPip
  • Advanced Member
  • 188 posts
  • LocationBradford - UK

Posted 26 June 2006 - 10:25 AM

[!--quoteo(post=388000:date=Jun 26 2006, 11:12 AM:name=Jus)--][div class=\'quotetop\']QUOTE(Jus @ Jun 26 2006, 11:12 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Interesting. Were you able to find a way around it?
[/quote]


Well!!

At this time i was not as experianced with php as i am now and all of the submissions were going to one address so either i would allow an exception on the anit-spammer or i would not place a from address in the from header which would automatically give you an address of eg. username@server1.webhost.com which was fine as like i said only one address recieved the email.

Now i would prob have used a IMAP command and used that address purly for sending out as this type of email thatway everything would resolve back to the mailserver.

When all else fails - Try reading the manual.

Integrated IT Systems Ltd


#7 Jus

Jus
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 June 2006 - 10:28 AM

I can't even get a "From" to show up at all. I wish I had that problem.

No matter what I do to $From or where I put it, the email shows up as unknown sender with the from field blank. Any ideas?

#8 d_barszczak

d_barszczak
  • Members
  • PipPipPip
  • Advanced Member
  • 188 posts
  • LocationBradford - UK

Posted 26 June 2006 - 10:43 AM

[!--quoteo(post=388009:date=Jun 26 2006, 11:28 AM:name=Jus)--][div class=\'quotetop\']QUOTE(Jus @ Jun 26 2006, 11:28 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I can't even get a "From" to show up at all. I wish I had that problem.

No matter what I do to $From or where I put it, the email shows up as unknown sender with the from field blank. Any ideas?
[/quote]

Just had a quick look at your code and it would seem your trying to put your From header in from a variable. I would do a quick check to make sure that the variable has data in it at this point. And maybe as a test manually enter the from header just to see if it is your variable or your coding thats causing the problem.


Below is a simple code i got off php.net

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com'

mail($to, $subject, $message, $headers);
?> 

When all else fails - Try reading the manual.

Integrated IT Systems Ltd


#9 Jus

Jus
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 June 2006 - 12:32 PM

My code has elements of that (code posted above).. it just doesn't work. The "from" stays blank

#10 d_barszczak

d_barszczak
  • Members
  • PipPipPip
  • Advanced Member
  • 188 posts
  • LocationBradford - UK

Posted 26 June 2006 - 12:54 PM

[!--quoteo(post=388045:date=Jun 26 2006, 01:32 PM:name=Jus)--][div class=\'quotetop\']QUOTE(Jus @ Jun 26 2006, 01:32 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
My code has elements of that (code posted above).. it just doesn't work. The "from" stays blank
[/quote]

Where is this variable set?: $array_user_email[0]

When all else fails - Try reading the manual.

Integrated IT Systems Ltd


#11 Jus

Jus
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 June 2006 - 01:16 PM

n/m I got it. I was editing the wrong "from"...the one lower on the page, instead of the one you're looking at, with $array_user_email[0]

Works perfectly now. Thx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users