【问题标题】:PHP mail error domain missing or malformed<EOL>PHP 邮件错误域丢失或格式错误<EOL>
【发布时间】: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


【解决方案1】:

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

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

不需要为此使用关联数组。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    相关资源
    最近更新 更多