views:

46

answers:

3

Any help would be much appreciated. Here is the code:

<?php include 'header_admin.php'; ?>
<?php
include 'dbc.php';
page_protect();
checkAdmin();
?>
<?PHP
require_once "Mail.php";

$con = mysql_connect("host","username","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db_name", $con);

$elist = mysql_query("SELECT cEmail FROM tblUsers WHERE intUserID = '20'");

$from = "FROM E-MAIL";
$subject = $_POST['eSubject'];
$body = $_POST['eMessage'];

$host = "smtp.domain.com";
$port = "465";
$username = "username";
$password = "password";

echo "<div class='entry'>"; 

if(mysql_num_rows($elist) > 0)
{                   
    while($eresult = @mysql_fetch_array($elist)) {
        $headers = array ('From' => $from, 'To' => $eresult['cEmail'], 'Subject' => $subject);
        $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
        $mail = $smtp->send($elist_result['cEmail'], $headers, $body);
    }   
}

echo "<table align='center'><p>Message successfully sent!</p></table></div>";

mysql_close($con);

?>

I made sure that the smtp settings were correct and I manually checked my mysql query to make sure it's grabbing the e-mail address. also, I did a separate "echo" command to make sure $body and $subject were correct.

A: 

Try using the PHP mail function: http://php.net/manual/en/function.mail.php

Fosco
A: 

You use there $elist_result['cEmail'] , if it differs from $eresult['cEmail'] , where does it come from?
Its not obvious from the code posted above.(guess it's just a typing error)

Dr.Molle
That's a typo. It's the $eresult['cEmail'] the result from the sql query
BigMike
A: 

The $smtp->send() method returns a PEAR_Error object if something blows up (or boolean TRUE if the call succeeded). Change your code to something like this:

$ret = $smtp->send();
if ($ret !== TRUE) {
    echo "Mail send failed: ", $err::getMessage();
}

which should echo out any details of the failure for you.

Marc B