Jump to content

Archived

This topic is now archived and is closed to further replies.

Jus

why would a form only work for some emails?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
thanks for the quick response...

[code]    # 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);

}
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Interesting. Were you able to find a way around it?

Share this post


Link to post
Share on other sites
[!--quoteo(post=388000:date=Jun 26 2006, 11:12 AM:name=Jus)--][div class=\'quotetop\']QUOTE(Jus @ Jun 26 2006, 11:12 AM) [snapback]388000[/snapback][/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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[!--quoteo(post=388009:date=Jun 26 2006, 11:28 AM:name=Jus)--][div class=\'quotetop\']QUOTE(Jus @ Jun 26 2006, 11:28 AM) [snapback]388009[/snapback][/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

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

mail($to, $subject, $message, $headers);
?>
[/code]

Share this post


Link to post
Share on other sites
My code has elements of that (code posted above).. it just doesn't work. The "from" stays blank

Share this post


Link to post
Share on other sites
[!--quoteo(post=388045:date=Jun 26 2006, 01:32 PM:name=Jus)--][div class=\'quotetop\']QUOTE(Jus @ Jun 26 2006, 01:32 PM) [snapback]388045[/snapback][/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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.