Mail headers

Discussion in 'PHP' started by web@master24, Jul 28, 2009.

  1. #1
    Hi, im have 2 websites in my server, one is with vbulletin and other is a custom script, when i send emails from vbulletin, all users get the email in the inbox, but when i send from the other the users get the email in the spam folder, and no its the domain because no its in the blacklist, i think what is the headers, the file what sent the email is this:

    <? 
    class Mailer
    {
       /**
        * sendWelcome - Sends a welcome message to the newly
        * registered user, also supplying the username and
        * password.
        */
       function sendWelcome($user, $email, $pass){
          global $settings,$HTTP_SERVER_VARS;
    	  $from = "From: ".$HTTP_SERVER_VARS['SERVER_ADMIN']." <".$HTTP_SERVER_VARS['SERVER_ADMIN'].">";
          $subject = "Bienvenido a MiMp3 ".$user;
          $body = $user.",\n\n"
                 ."Bienvenido .$user! Te acabas de registrar en ".$settings['site_title']
                 ." tus datos de acceso son::\n\n"
                 ."Username: ".$user."\n"
                 ."Password: ".$pass."\n\n"
                 ."Ahora ya puedes disfrutar de todos los beneficios que tienes al formar parte de "
                 ."MiMp3.net, como crear tu playlist, descargar de megavideo y megaupload, entre algunas otras. "
                 ."Te recomendamos que entres ahora a MiMp3, inicies sesion y cambies tu contraseña en Mi cuenta "
                 ."para que la recuerdes facilmente. "
                 ."Cualquier comentario envialo a webmaster@mimp3.net | atte. Johnatan G. Webmaster.\n\n"
                 ."- ".$settings['site_title']."\n".$settings['urlname'];
    
          return mail($email,$subject,$body,$from);
       }
       
       /**
        * sendNewPass - Sends the newly generated password
        * to the user's email address that was specified at
        * sign-up.
        */
       function sendNewPass($user, $email, $pass){
          global $settings,$HTTP_SERVER_VARS;
    	  $from = "From: ".$HTTP_SERVER_VARS['SERVER_ADMIN']." <".$HTTP_SERVER_VARS['SERVER_ADMIN'].">";
          $subject = "Tu nueva contraseña ".$user;
          $body = $user.",\n\n"
                 ."Te generamos tu nueva contraseña, devido a que la solicitaste en MiMp3.net, "
                 ."si no lo hiciste porfavor haz caso omiso a este mensaje, de lo contrario "
                 ."inicia sesion con los siguientes datos en  ".$settings['site_title'].".\n\n"
                 ."Username: ".$user."\n"
                 ."New Password: ".$pass."\n\n"
                 ."Te recomendamos que cambies tus datos de acceso "
                 ."por algo facil de recordar, "
                 ."lo puedes hacer en Mi Cuenta "
                 ."despues de que hayas iniciado sesion.\n\n"
                 ."- ".$settings['site_title']."\n".$settings['urlname'];
                 
          return mail($email,$subject,$body,$from);
       }
    };
    
    /* Initialize mailer object */
    $mailer = new Mailer;
     
    ?>
    
    PHP:
    what headers can i use for hotmail, gmail, etc received the mail in the inbox. Thanks i hope somebody can help me
     
    web@master24, Jul 28, 2009 IP
  2. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #2
    Use phpMailer or use following function
    
    function send_mail($myname, $myemail, $contactname, $contactemail,$subject, $message){
    $headers ="";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html;\n\tcharset=\"iso-8859-1\"\n";
    $headers .= "X-Priority: 3\n";
    $headers .= "X-MSMail-Priority: Normal\n";
    $headers .= "X-Mailer: MyMailer\n";
    $headers .= "To: \"$contactname\" <$contactemail>\n";
    $headers .= "From: \"$myname\" <$myemail>\n";
    $headers .= "Reply-To: \"$myname\" <$myemail>\n"; 
    return( mail( $contactemail, $subject, urldecode($message), $headers ) );
    }
    
    PHP:
     
    greatlogix, Jul 28, 2009 IP
  3. wrxbuzz

    wrxbuzz Peon

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Both Hotmail and Gmail supports HTML based e-mails, but if you would like to make sure EVERYONE is seeing your e-mails simply send it in clear text.

    Also the piece of code you copied above doesn't include the mail header generator, its just the function which controls the E-mail address, Subject and the Body of the message. This will not tell you much on how the mail will be received by the recipient. Try to look into your forum config, usually you can switch there between HTML based e-mails and TEXT based.

    Goodluck!
     
    wrxbuzz, Jul 28, 2009 IP
  4. web@master24

    web@master24 Active Member

    Messages:
    418
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    90
    #4
    Im add this headers:

    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    and now works, gmail and hotmail received in the inbox, thanks for help
     
    web@master24, Jul 28, 2009 IP