我想使用的PHPMailer發出簡訊,但每次我試圖觸發它的時候我不斷收到以下錯誤。我不確定我的sql語法是否正確?PHPMailer的投擲MySQL錯誤
Warning: mysql_fetch_array() : supplied argument is not a valid MySQL result resource in view.html.php(38):eval()'d code on line 32
<?php
$formid = $_GET[token];
$templatequery = mysql_query("
SELECT *
FROM hqfjt_chronoforms_data_addmailinglistmessage
WHERE cf_id = '$formid'"
) or die(mysql_error());
$templateData = mysql_fetch_object($templatequery);
$gasoiluserTemplate = $templateData->gasoilusers;
$dervuserTemplate = $templateData->dervusers;
$kerouserTemplate = $templateData->kerousers;
$templateMessage = $templateData->mailinglistgroupmessage;
?>
<?php
require_once('./send/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
// $body = file_get_contents('contents.html');
$body = 'Dear Test this is a test.';
// $body = preg_replace('/\\\\/i', $body);
$mail->SetFrom('[email protected]', 'List manager');
$mail->AddReplyTo('[email protected]', 'List manager');
$mail->Subject = "Mailing List Test";
$query = "
SELECT leadname,businessname,email
FROM hqfjt_chronoforms_data_addupdatelead
WHERE keromailinglist='$kerolist'
AND dervmailinglist='$dervlist'
AND gasoilmailinglist='$gasoillist'";
$result = @MYSQL_QUERY($query);
while ($row = mysql_fetch_array ($result)) {
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress($row["email"], $row["full_name"]);
$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
if(!$mail->Send()) {
echo "Mailer Error (" . str_replace("@", "@", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
} else {
echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "@", $row["email"]) . ')<br>';
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
?>
編輯>>>>>>
我現在已經添加了錯誤檢查,但現在只是得到了一個空白頁,沒有錯誤,也沒有郵件?
<?php
$formid = $_GET[token];
$templatequery = mysql_query("SELECT * FROM hqfjt_chronoforms_data_addmailinglistmessage WHERE cf_id = '$formid'") or die(mysql_error());
$templateData = mysql_fetch_object($templatequery);
$gasoiluserTemplate = $templateData->gasoilusers;
$dervuserTemplate = $templateData->dervusers;
$kerouserTemplate = $templateData->kerousers;
$templateMessage = $templateData->mailinglistgroupmessage;
?>
<?php
require_once('./send/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
// $body = file_get_contents('contents.html');
$body = 'Dear Test this is a test.';
// $body = preg_replace('/\\\\/i', $body);
$mail->SetFrom('[email protected]', 'List manager');
$mail->AddReplyTo('[email protected]', 'List manager');
$mail->Subject = "Mailing List Test";
$query = "SELECT leadname,businessname,email FROM hqfjt_chronoforms_data_addupdatelead WHERE keromailinglist='$kerolist' AND dervmailinglist='$dervlist' AND gasoilmailinglist='$gasoillist'";
$result = mysql_query($query);
// Bail out on error
if (!$result)
{
trigger_error("Database error: ".mysql_error()." Query used was: ".htmlentities($query), E_USER_ERROR);
die();
}
while ($row = mysql_fetch_array ($result)) {
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress($row["email"], $row["full_name"]);
$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
if(!$mail->Send()) {
echo "Mailer Error (" . str_replace("@", "@", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
} else {
echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "@", $row["email"]) . ')<br>';
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
?>
爲什麼您使用@MYSQL_QUERY – 2012-01-10 20:01:54
嘗試在你的MYSQL_QUERY($查詢)行的前面去掉@符號,看看它在做什麼。你很可能會壓制一個錯誤信息,告訴你更詳細的問題。 – Tanoro 2012-01-10 20:02:57