PHP 邮件错误域丢失或格式<EOL>不正确



我正在尝试向数据库中设置的客户电子邮件发送邮件。

$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";
}

这是我需要将电子邮件发送到数据库外的电子邮件的代码。

但当我尝试发送它时,我会收到错误::域丢失或格式错误

您只需要地址,这是您获取的唯一字段,所以我选择:

$query = ("SELECT email FROM ps_customer where id_customer = 2");
$result = $dbc->query($query);
$row = $result->fetch_row();
$to_email = $row[0];

无需为此使用assoc数组。

您尚未提及,但您发送的消息可能会被拒绝。您通过mail()发送,这意味着您不是通过gmail的服务器发送,而是使用来自地址的gmail。这是伪造的,意味着你的邮件将被退回或垃圾邮件过滤。使用mail()(除了不使用来自地址的gmail(无法解决此问题;你需要使用SMTP通过使用PHPMailer的gmail发送(你用它标记了这个问题(。

相关内容

最新更新