Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8558205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:45:28+00:00 2026-06-11T15:45:28+00:00

Possible Duplicate: How do you email source code without getting flagged as spam? How

  • 0

Possible Duplicate:
How do you email source code without getting flagged as spam?
How can I lower the spam score of my email message?

I’m using the code below to send an email with attachment through PHP. (Just a medium sized image and a small description without any spam ish content)

The problem is that some services flagging the email as spam or completely reject it.

I’m new to PHP and found this code here on SO. Is there anything wrong with the headers or what could cause this?

<?php
    $file         = $_POST["thefile"];         
        $text_message = $_POST["themessage"];       
        $subject      = $_POST["thesubject"];        
        $from         = $_POST["thesender"];        
        $to           = $_POST["theaddress"];                 

          $attachment=uniqid(rand(), true) . '.png';

       $headers="From: $from\r\n";
        $headers.="Reply-to: $from\r\n";
        $headers.="Return-Path: $from\r\n";

    if (isset($_ENV["SERVER_NAME"])) 
        $headers.="Message-Id: <" . md5(uniqid(microtime())) . "@" . $_ENV["SERVER_NAME"] . ">\r\n";
    else
        $headers.="Message-Id: <" . md5(uniqid(microtime())) . "@" . 'unknown' . ">\r\n";
    $headers.="Date: " . date("r") . "\r\n";
    $headers.="X-Mailer: PHP\r\n";
    if (isset($_ENV["REMOTE_ADDR"])) 
        $headers.="X-SenderIP: " . $_ENV["REMOTE_ADDR"] . "\r\n";
    else
        $headers.="X-SenderIP: " . 'unknown' . "\r\n";
    if (isset($_ENV["SERVER_NAME"])) 
        $headers.="X-WebSite: " . $_ENV["SERVER_NAME"] . "\r\n";
    else
        $headers.="X-WebSite: " . 'unknown' . "\r\n";
    $headers.="X-Script: SWF_Generator\r\n";
    $bound_text=md5(uniqid(time()));

        $headers.="MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed; boundary=\"PHP-mixed-$bound_text\"\r\n";
        $message="--PHP-mixed-$bound_text\r\n"      
                ."Content-Type: text/html; charset=\"utf-8\"\r\n"
                ."Content-Transfer-Encoding: 7bit\r\n\r\n"  
                ."<html><head></head><body>"
                ."<div style=\"font-family: Arial, Helvetica, sans-serif; font-size : 1.3em; color: #000000;width: 100%;text-align: left;\">$text_message</div></body></html>\r\n\r\n"  
                ."--PHP-mixed-$bound_text\r\n"  
                ."Content-Transfer-Encoding: base64\r\n"
                ."Content-Disposition: attachment; filename=\"$attachment\"\r\n"
                ."Content-Type: image/png; name=\"$attachment\"\r\n\r\n"
        .chunk_split($file)
        ."\r\n\r\n"
                ."--PHP-mixed-$bound_text--\r\n\r\n";

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

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:45:29+00:00Added an answer on June 11, 2026 at 3:45 pm

    Well, sending emails using PHP is not as simple as calling the mail() function…

    I suggest you to use a valid SMTP server (a gmail one, for instance) and a ready-made php component/class like PHPmailer.

    That should be enough for 99% cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Sending Email in Android using JavaMail API without using the default android
Possible Duplicate: Sending Email in Android using JavaMail API without using the default/built-in app
Possible Duplicate: delaying the sending of email messages without using Thread.Sleep c# so i
Possible Duplicate: Send email using System.Net.Mail through gmail. (C#) I am using this code
Possible Duplicate: Sending Email in Android using JavaMail API without using the default Android
Possible Duplicate: mail() header problem for html email I'm using the following for $headers
Possible Duplicate: How to check if an email address exists without sending an email?
Possible Duplicate: PHPMailer AddAddress() Here is my code. require('class.phpmailer.php'); $mail = new PHPMailer(); $email
Possible Duplicate: Git over Email I'm new to Git and am interested in using
Possible Duplicate: Using square brackets in hidden HTML input fields What can I do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.