Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP邮件与数据库_Php_Mysql - Fatal编程技术网

PHP邮件与数据库

PHP邮件与数据库,php,mysql,Php,Mysql,我正在从数据库中提取信息,并试图将其作为电子邮件发送。将从数据库中提取多行数据。这就是我的代码看起来的样子 <?php $to = "--"; $subject = "Test mail"; $message .= "This Week's Memo: "; while ($row = mysqli_fetch_assoc($result)){ $message .= $row["first_name"]; $message .= (date ('F-d ', strtotime($ro

我正在从数据库中提取信息,并试图将其作为电子邮件发送。将从数据库中提取多行数据。这就是我的代码看起来的样子

<?php
$to = "--";
$subject = "Test mail";
$message .= "This Week's Memo: ";

while ($row = mysqli_fetch_assoc($result)){
$message .= $row["first_name"];
$message .= (date ('F-d ', strtotime($row["time"])));
$message .= $row["title"];
$message .= $row["memo"];
};


$from = "--";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
试试:

$message.=$row[“title”]。
; $message.=$row[“memo”];
只需添加它即可。在标题后连接新行

$message .= $row["title"] ."\n";
作为旁注,我建议您开始声明消息变量,然后连接其他字符串

$message = "This Week's Memo: ";
       //^ no dot at first declaration

使用PHP_EOL在不同的操作系统上工作

$message .= $row["title"].PHP_EOL;

连接“
”只会将
添加到电子邮件中。所有内容仍在内联中…该\n工作正常。我需要更好地了解如何提取标签并将其输入数据库…@user1075004是的!我很高兴我帮了你!PHP_EOL?我想这就到此为止了?是的,windows上的PHP\u EOL\r\n Linux上的PHP\r\n排除了猜测工作这应该是正确的答案。它是使用标准PHP\u EOL编写的,而不是单独使用“\n”。
$message .= $row["title"].PHP_EOL;