Jump to content

ADD CC EMAIL FROM ARRAY


ladrajeshwar

Recommended Posts

Dear All,

 

After my first post where I was using sendmail to send CC emails and was not going through i did a research myself and did find out that lot of the servers not allow CCing. So i did a change to my php and used smtp verification.. Still what it does is send CC email to the last email in the result and not to all the results that exist... Any help would be appreciated... Now the php is as follows:

 

<?php

require_once "Mail.php";

$hostname = " ";

$username = " ";

$password = " ";

$dbname = " ";

$usertable = " ";

 

//Query db

mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");

$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");

 

$query = "SELECT email FROM test WHERE DATE >CURDATE() OR DATE <CURDATE()";

$result = mysql_query($query) or die(mysql_error());

$num=mysql_numrows($result);

 

$query1 = "SELECT NAME,EMAIL FROM test WHERE DATE=CURdate()";

$result1 = mysql_query($query1) or DIE("Could not Execute Query on table $usertable");

$num1=mysql_numrows($result1);

 

if($num1 == 0)

 

die("No Birth Day Today");

 

 

$recipientAddr=mysql_result($result1,$i,"email");

$name=mysql_result($result1,$i,"name");

 

echo "$recipientAddr<br>";

echo "$name<br>";

echo "$num1<br><br>";

 

 

$num=mysql_numrows($result);

 

$i=0;

 

echo "CC: ";

while ($row = mysql_fetch_array($result)) :

 

if ($i< $num)

{

$ccaddr=mysql_result($result,$i,"email");

echo "$ccaddr;";

$i++;

}

else

{

echo "<font face=verdana color=red size=1>NO CC ADDRESS FOUND</font>";

}

endwhile;

 

//Set mail variables

$subject .= "Birthday Wishes";

$from = "EMAIL ADDRESS NAME <[email protected]>";

$body = "We would like to take this opportunity to wish you a VERY HAPPY BIRTHDAY";

 

 

$host = "smtp.myhost.com";

$username = "[email protected]";

$password = "********";

 

$headers = array ('From' => $from, 'To' => $recipientAddr, 'Cc' => $ccaddr, 'Subject' => $subject);

$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));

 

$mail = $smtp->send($recipientAddr, $headers, $body);

 

if (PEAR::isError($mail)) {

echo("<p>" . $mail->getMessage() . "</p>");

} else {

echo("<p>Message successfully sent!</p>");

}

echo "$recipientAddr<br>";

echo "$name<br>";

 

mysql_free_result($result);

 

?>

Link to comment
https://forums.phpfreaks.com/topic/230684-add-cc-email-from-array/
Share on other sites

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.