Jump to content

php email - sending many emails


Birdmansplace

Recommended Posts

So i have this email scrip in php to long into my smtp server and sent email to users in the contacts list.  Well for some time know i have been trying to figure out what is causing it to send 3 emails of the same content to each and every user.  They are getting sick of it. I also have code in the script to echo the names of who the email has been sent to.

 

list file:

<?php
//Users name

$to = "[email protected]";
$nameto = "Users name";
$Randy = "$nameto";
$from = "[email protected]";
$namefrom = "Birdmansplace Admin";
$subject = "Automated message!";
$message = "Message";
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
?>

 

Email php script:

<?php require_once('html/list.html'); ?>



<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "smtpserver";
$port = "25";
$timeout = "30";
$username = "username";
$password = "password";
$localhost = "localhost";
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */

//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}

//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";

//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";

//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";

//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";

//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";

//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";

// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
}
echo "Emails to dominos employees have been sent";
echo "<br />";
<!--echoing users names-->
echo "$User names";


?>
</body>
</html>

 

Any idea how to stop this from happening or better yet a smarter way to do it.

 

Thanks for the help

 

Link to comment
https://forums.phpfreaks.com/topic/188887-php-email-sending-many-emails/
Share on other sites

The issue i am having is if there is only one email to send to it works fine but more than one it sends it 3 times per email address. The web server runs on my lan.  When i send the emails from anywhere on the lan it sends everyone 1 email.  I have tested this out side my lan via wan and if i send one emil to one person it sends with out doubling up or more but as soon as i send more then one in the script it sends 3 each and everytime regardless of sever wan/lan load.

 

I have a list of atleast 5 at the moment that are being emailed the same info.  any idea what i can do or change in the code. I am trying to avoid havein the script for each and every email and have to do each and every one manually.

 

 

Thanks

For advanced email, I will suggest using any library for email. There are plenty in PHP.

I tried many times in early days and found that it is not good to use mail() function simply as it takes lots of time to debug and correct and finally I was forced to switch to library. Check for PHPmailer.

you can read this post also: http://www.satya-weblog.com/2007/03/php-mail-scripts_17.html

Archived

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

×
×
  • Create New...

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.