0

我有一个按钮,当按下它时,它将通过电子邮件发送数据库中电子邮件的更新。

这是我的代码。我也从论坛上得到了这个,但我不知道它没有在数据库中收到电子邮件是怎么回事:

$form_action = $_POST['form_action'];
if ($form_action == 'REGISTER') {

//send to your self
$to ="admin@admin.com";

$subject = 'System Email';

// message
$message = "<html>".
"<head>".
" <title>System Email</title>".
"</head>".
"<body>".
"message here!".
"</body>".
"</html>";

//get email list

//open database connection
$username = "root";
$password = ""; //input your password here.
$database = "dbase";
//connect to database
$link=mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("<b>Unable to specified database</b>");

$query="SELECT email_address FROM db_other_details";
$result=mysql_query($query) or die('Error, query failed');
mysql_close($link);

$row=1;
$numrows=mysql_num_rows($result);
$bccfield="Bcc: ". mysql_result($result,0,"email_address");
while($row<$numrows)
{
$email=mysql_result($result,$row,"email_address");
$bccfield .= "," . $email; //seperate by comma 
$row++;
}
$bccfield .= "\r\n";

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= $bccfield;

$headers .= 'From: System <admin@admin.com>' . "\r\n";

// Mail it
mail($to, $subject, $message,$headers);

 if (mail($to,$subject,$message,$headers)) {
   header("Location: ".WEBSITE_URL."email-all.html?result=success");
} else {
    header("Location: ".WEBSITE_URL."email-all.html?result=failed");
}
}

switch (trim($_GET['result'])) {
    case "failed":
        $sendmail_result    = "failed";
        $form_message       = "Cannot send email to " . $numrows . "registrants at this time. Please try again later.";
        break;
    case "success":
        $sendmail_result    = "success";
        $form_message       = "Email sent to" . $numrows ." registrants.";
}

关于如何做到这一点的任何建议?我在这里用同样的问题检查了其他一些主题,但没有帮助。

谢谢!

4

2 回答 2

0

您应该尝试以下替代方案。

http://swiftmailer.org/

http://code.google.com/a/apache-extras.org/p/phpmailer/

于 2013-01-21T06:44:47.597 回答
0

1) 使用 PDO。

2) 确保您有关于 php.ini 的错误消息。

3) var_dump / print_r 你的变量& GET 请求来查看数据是否可用。

4) 检查 mysql 错误日志是否有潜在的查询错误。

5) 在使用 php::mail() 函数发送数据之前,对您的数据进行 UTF-8 编码。

于 2013-01-21T06:52:09.523 回答