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 6737773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:17:18+00:00 2026-05-26T11:17:18+00:00

I have a small script that I wrote to send an email out to

  • 0

I have a small script that I wrote to send an email out to about 200 customers. The issue is that the script is running on a small hosting site, and I need to use my companies email address as the sender. This would be fine, except most if not all of my customers have robust spam filters that will block my message if the sending domain isn’t the same as the sender’s email address domain (aka, I’m hosting the script at ‘example.com’, but my email is ‘business@company.com’.

I’ve tried SMTP’ng into a gmail account and sending that way (as a test before I send it from the company email), but it doesn’t seem to work, it still has all the headers of my domain.

Any suggestions on what I’m doing wrong? Is there another way to do this?

The SMTP code I’m using:

if (!$this->valid_mail_adresses) return; 

//connect to the host and port
$smtpConnect = fsockopen($this->smtpServer, $this->port, $errno, $errstr, $this->timeout);
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
    $this->msg[] = "Failed to connect: $smtpResponse";
    var_dump($this->msg);
    return;
}
else
{
    $logArray['connection'] = "<p>Connected to: $smtpResponse";
    echo "<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
}

//you have to say HELO again after TLS is started
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse2'] = "$smtpResponse";

//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";

//send the username
fputs($smtpConnect, base64_encode($this->username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";

//send the password
fputs($smtpConnect, base64_encode($this->password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";

//email from
fputs($smtpConnect, "MAIL FROM: <{$this->from_mail}>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";

//email to
fputs($smtpConnect, "RCPT TO: <$this->mail_to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";

//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";


$mail_message = $this->mail_body; 
if (count($this->att_files) > 0)
{ 
    foreach ($this->att_files as $val)
        $mail_message .= $val; 
    $mail_message .= "--".$this->uid."--"; 
} 
    if (mail($this->mail_to, $this->mail_subject, $mail_message, $this->mail_headers)) { 
        $this->msg[] = "Your mail is succesfully submitted."; 
} else
    $this->msg[] = "Error while sending you mail."; 


//construct headers
//$headers = "MIME-Version: 1.0" . $newLine;
//$headers .= "Content-type: multipart/mixed; boundary=\"{$this->uid}\" charset=iso-8859-1" . $newLine;
$headers .= $this->mail_headers;
//$headers .= "To: {$this->to_name} <{$this->mail_to}>" . $newLine;
//$headers .= "From: {$this->name_from} <$from>" . $newLine;

$message = "To: {$this->mail_to}\r\nFrom: {$this->from_mail}\r\nSubject: {$this->mail_subject}\r\n$headers\r\n\r\n{$this->mail_body}\r\n";
if (count($this->att_files) > 0)
{ 
    foreach ($this->att_files as $val)
        $message .= $val; 
    $message .= "--".$this->uid."--"; 
} 
echo $message;
print_r($logArray);
//observe the . after the newline, it signals the end of message
//fputs($smtpConnect, $message);
//$smtpResponse = fgets($smtpConnect, 4096);
//$logArray['data2response'] = "$smtpResponse";

// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
return($logArray);
  • 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-05-26T11:17:18+00:00Added an answer on May 26, 2026 at 11:17 am

    You might try using SwiftMailer which handles almost all parts of sending an email through almost any means. Including logging into an email account and sending through that. It’s written in PHP, so you can view/change the code.

    http://swiftmailer.org/

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

Sidebar

Related Questions

I have a small script that I am try to port to work for
I have a small cgi script that fetches and validates a configuration file for
I have a script that animates a small DIV popping up on the page.
I have this small script that sorts the content of a text file #
I'm facing a weird issue. I wrote a small server in C++ that stores
I have written a small little script that looks up a work on wikipedia
I have a small script that I use to resize all of the images
I just wrote a small python script that gets me all the groups on
I have a small script that launches and, every half hour, feeds a command
I have a small crawler/screen-scraping script that used to work half a year ago,

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.