Jump to content

PHP Email


ladrajeshwar

Recommended Posts

Dear All,

 

I have the following script which is supposed to send Birthday Wish email. There might be single or multiple recipient on the same day which will be in TO field. Whereas all other email address in the database would be send a CC. The issue is that the echo of the $ccaddr works fine and prints all other email address from database but does not include in the header of the email...

 

Any help would be appreciated as im a newbie to php.. :-)

 

 

<?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\n";

$headers .= "Content-Type: text/html; charset=iso-8859-1\n";

$headers .= "From: [email protected] \n";

$headers .= "Reply-to: [email protected] \n";

$headers .= "CC: $ccaddr; \n";

 

 

$mailBodyText = <<<HHHHHHHHHHHHHH

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

</head>

<body>

<font face=verdana size=1>

Dear $name</font><br><br>

 

We would like to take this opportunity to wish you a VERY HAPPY BIRTHDAY

 

</body>

HHHHHHHHHHHHHH;

 

 

//send mail

mail($recipientAddr, $subject, $mailBodyText, $headers);

 

 

 

mysql_free_result($result);

 

echo "email sent successfully<br>";

 

?>

Link to comment
https://forums.phpfreaks.com/topic/230594-php-email/
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.