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 <xyz@abc.com>";

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

 

 

$host = "smtp.myhost.com";

$username = "xyz@abc.com";

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.