Weird problem when sending email from a PHP form.

Discussion in 'Installation/Configuration' started by edge, Sep 5, 2006.

  1. edge

    edge Active Member Moderator

    I've got this online registration for that will send a confirmation email back to the user.
    The problem is that when the email is send from the form it will show "[email protected]"
    Problem with this is that there is no SPF record for this, causing some registrations not to get to the user (hotmail does not accept mail when SPF is wrong)

    Now my HOSTNAME is host.domainname.tld, so I thought by adding host.domainname.tld to the existing SPF record for domainname.tld would fix it.
    Wrong.. The problem is still their.

    The problem is the from: [email protected]
    I think if it would read [email protected] that all is okay!

    I've had a look at PHP.ini, but see nothing where I can set this.

    Anyone here who might know how to fix this problem?

    This is the data from the: mail.info file
    (note that I have changed some things for privacy reasons)
    I have changed the domainname.tld, the email_address, an_email_address and the IP: 11.22.33.44


    When sending from the PHP form:
    When sending with SMTP (and all is ok!):
     
    Last edited: Sep 5, 2006
  2. sjau

    sjau Local Meanie Moderator

    Well, you could set a sender in the PHP form.
     
  3. Ben

    Ben Active Member Moderator

    Can you post the php code?

    What you additianlly can do is to set the -f parameter for sendmail in the php.ini to fix set the from address, wich is a real from address and no x-from address...
     
  4. edge

    edge Active Member Moderator

    This is part of the password recover code:

    PHP:
    if($_REQUEST['recover'])
    {
        
    STemplate::assign('receiver_name'$rs->fields['username']);
        
    STemplate::assign('receiver_fname'$rs->fields['fname']);
        
    STemplate::assign('receiver_lname'$rs->fields['lname']);
        
    STemplate::assign('password'$rs->fields['pwd']);
        
        
    $rs $conn->execute("select * from emailinfo where email_id='recover_password'");
        
    $subj $rs->fields['email_subject'];
        
    $email_path $rs->fields['email_path'];
        
    $body STemplate::fetch($email_path);
        @
    mailing($_REQUEST['email'], $config['site_name'], $config['admin_email'], $subj$body);
        
        
    $msg "An email is sent to your email address. Plese check it now.";
        
        
    header("Location: recoverpass.php?msg=$msg");
    }
    This is how the main mail function looks:
    PHP:
    //MAIL FUNCTIION
    function mailing($to,$name,$from,$subj,$body,$bcc=""
    {
        global 
    $SERVER_NAME;
        
    $subj=nl2br($subj);
        
    $body=nl2br($body);
        
    $recipient $to;
        if(
    $bcc!=""$headers "Bcc: " $bcc."\n";
        
    $headers .= "From: " $from "\n";
        
    //$headers .= "X-Sender: <" . "$to" . ">\n";
        //$headers .= "Return-Path: <" . "$to" . ">\n";
        //$headers .= "Error-To: <" . "$to" . ">\n";
        
    $headers .= "Content-Type: text/html\n";
        
    mail("$recipient","$subj","$body","$headers");
    }
    and a small part of the signup form

    PHP:
                        {
                                
    $expired_time date("Y-m-d H:i:s"strtotime("+".$rs->fields['trial_period']." day"));
                        
                                
    $sql "update subscriber set
                                        pack_id=
    $_REQUEST[pack_id],
                                        subscribe_time='"
    .date("Y-m-d H:i:s")."',
                                        expired_time='
    $expired_time'
                                        where UID = 
    $userid";
                                
    $conn->execute($sql);
                                
                                
    SESSION_REGISTER("UID");            $_SESSION[UID]=$userid;
                                
    SESSION_REGISTER("EMAIL");            $_SESSION[EMAIL]="$_REQUEST[email]";
                                
    SESSION_REGISTER("USERNAME");        $_SESSION[USERNAME]="$_REQUEST[username]";
                                
    SESSION_REGISTER("EMAILVERIFIED");    $_SESSION[EMAILVERIFIED]="no";
                                
    ####################### Email                
                                
    $ran=time().rand(1,99999999);
                                
    $sql="update verify as v, signup as s set
                                                v.vcode='
    $ran',
                                                s.emailverified='no' WHERE v.UID=s.UID and v.UID='
    $userid'";
                                
    $conn->execute($sql);
                                
    STemplate::assign('vcode',$ran);

                                
    $to=$_SESSION[EMAIL];
                                
    $name=$config['site_name'];
                                
    $from=$config['admin_email'];
                                
    $rs $conn->execute("select * from emailinfo where email_id='verify_email'");
                                
    $subj $rs->fields['email_subject'];
                                
    $email_path $rs->fields['email_path'];
                                
                                
    $mailbody=STemplate::fetch($email_path);
                                
    mailing($to,$name,$from,$subj,$mailbody);
                                
    $msg "A verification email is sent to your address. Please check your email.";
                                
    ##################### end Email SECTION 

                                
    if($_REQUEST['next']!="")$page=$_REQUEST['next'].".php";else $page="invite_signup.php";
                                if(
    $_REQUEST['add']!="")$add=base64_decode($add);
                                        
    header("Location:$config[baseurl]/$page?$add");exit;
                        }
    Not sure if this is all what is needed to fix the problem (it's not my code)
     
    Last edited: Sep 5, 2006
  5. Ben

    Ben Active Member Moderator

    Well I splitted my lines of the header with \r\n instead of only \n but I'm note sure if there was a change or not...

    So my header var looks e.g. sth like this, if I don't use Pear's Mail class.
    PHP:
    $header "MIME-Version: 1.0\r\n";
    $header .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $header .= "From: [email protected] <[email protected]>\r\n";
     
  6. edge

    edge Active Member Moderator

    Thanks for the input, but I found the problem!

    In the mail function I had to replace: mail("$recipient","$subj","$body","$headers"); with mail("$recipient","$subj","$body","$headers","-f$from");

    (note the -f and $from)

    All is working fine now..
     

Share This Page