【发布时间】:2018-11-16 08:58:18
【问题描述】:
我正在尝试向我的数据库中设置的客户电子邮件发送邮件。
$subject = 'Testing PHP Mail';
$txt = 'This mail is sent using the PHP mail function';
$headers = "FROM: test@gmail.com";
$query = ("SELECT email FROM ps_customer where id_customer = 2");
$result = $dbc->query($query);
$row = $result->fetch_assoc();
echo $row['email'];
$to_email = (string)$row;
//while ($row = $result->fetch_assoc()) {
// echo $row['email'];
// $to_email = (string)'$row <@>';
if (mail($to_email, $subject, $txt, $headers)) {
echo "send";
} else {
echo "failed";
}
这是我需要将电子邮件发送到数据库之外的电子邮件的代码。
但是当我尝试发送它时,我收到错误::域丢失或 格式错误
【问题讨论】:
-
fetch_assoc返回一个数组。您现在将整个数组(作为字符串)放入目标地址。我猜你想要$row['email']这样的东西。 -
(string)$row返回字词Array。 -
我需要改变什么才能获得整个数组?
-
问题标签说您正在使用 PHPMailer,但您的代码甚至没有尝试使用该库。你能澄清一下吗?
标签: php mysql email phpmailer heidisql