I have a PHP script that I copied and modified from the
SourceForge.net website that I cannot get to work. The problem seems
to be that the value for $mail is not recognized. The script fails
at the if(!$mail-Send() ) and the unsuccessful message goes out.
Can somebody see what is wrong here? Thanks in advance.
<?
require("class. phpmailer.php") ;
$mail = new phpmailer();
$mail->IsMail();
$mail->From = "list@mydomain. com";
$mail->FromName = "List manager";
$mail->Host = "smtp.site.com" ;
$mail->Mailer = "smtp";
$dbh=mysql_conn ect ("localhost" , "mydb", "password") or die ('I cannot
connect to the database because: ' . mysql_error());
mysql_select_db ("mydb_mytable" );
$query = "SELECT fname, lname, email from mytable";
$result = @MYSQL_QUERY($q uery);
while ($row = mysql_fetch_arr ay ($result))
{
$fullname = $row["fname"] . " " . $row["lname"];
// HTML body
$body = "Hello <font size=\"4\">" . $fullname . "</font>, <p>";
$body .= "Here's the message." <br>";
$body .= "Sincerely, <br>";
$body .= "phpmailer List manager";
// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hello <font size=\"4\">" . $fullname . ", \n\n";
$text_body .= "Here's the messsage. \n";
$text_body .= "Sincerely, \n";
$text_body .= "phpmailer List manager";
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($ro w["email"]);
echo "The message:" . $mail. "<br>";
echo "Here's the message." . "<br>" . $body;
if(!$mail->Send())
echo "There has been a mail error sending to " .
$row["email"] . "<br>";
// Clear all addresses and attachments for next loop
$mail->ClearAddresses ();
}
?>
SourceForge.net website that I cannot get to work. The problem seems
to be that the value for $mail is not recognized. The script fails
at the if(!$mail-Send() ) and the unsuccessful message goes out.
Can somebody see what is wrong here? Thanks in advance.
<?
require("class. phpmailer.php") ;
$mail = new phpmailer();
$mail->IsMail();
$mail->From = "list@mydomain. com";
$mail->FromName = "List manager";
$mail->Host = "smtp.site.com" ;
$mail->Mailer = "smtp";
$dbh=mysql_conn ect ("localhost" , "mydb", "password") or die ('I cannot
connect to the database because: ' . mysql_error());
mysql_select_db ("mydb_mytable" );
$query = "SELECT fname, lname, email from mytable";
$result = @MYSQL_QUERY($q uery);
while ($row = mysql_fetch_arr ay ($result))
{
$fullname = $row["fname"] . " " . $row["lname"];
// HTML body
$body = "Hello <font size=\"4\">" . $fullname . "</font>, <p>";
$body .= "Here's the message." <br>";
$body .= "Sincerely, <br>";
$body .= "phpmailer List manager";
// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hello <font size=\"4\">" . $fullname . ", \n\n";
$text_body .= "Here's the messsage. \n";
$text_body .= "Sincerely, \n";
$text_body .= "phpmailer List manager";
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($ro w["email"]);
echo "The message:" . $mail. "<br>";
echo "Here's the message." . "<br>" . $body;
if(!$mail->Send())
echo "There has been a mail error sending to " .
$row["email"] . "<br>";
// Clear all addresses and attachments for next loop
$mail->ClearAddresses ();
}
?>
Comment