Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.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_Email - Fatal编程技术网

如何使用php发送电子邮件详细信息通知?

如何使用php发送电子邮件详细信息通知?,php,email,Php,Email,如何向使用php在我的表单中提供注册详细信息的用户发送电子邮件通知 我有运行完美的代码来给我发邮件,但现在我也想给我的用户提供同样的细节 我试图在我的数组中使用“$from”,但没有收到电子邮件 mymail.php <?php $subject = "Email Notification"; $message = "Thank you for your email"; $message = "Your Registering details are as follows:"; $mes

如何向使用php在我的表单中提供注册详细信息的用户发送电子邮件通知

我有运行完美的代码来给我发邮件,但现在我也想给我的用户提供同样的细节

我试图在我的数组中使用“$from”,但没有收到电子邮件

mymail.php

<?php

$subject = "Email Notification";
$message = "Thank you for your email";
$message = "Your Registering details are as follows:";
$message .= "<br><br>";
$message .= "<table border='1'>";
$message .= "<tr><td>Name</td><td>".$_POST['name']."</td></tr>";
$message .= "<tr><td>Email</td><td>".$_POST['email']."</td></tr>";
$message .= "</table>";

$from = $_POST['email'];
$to =  array('my_address@example.com', 'my_address2@example.com', $from);
$lp = "notification@example.com";

$headers = "MIME-Version: 1.0\r\n"; 

$headers .= "Content-type: text/html; charset=utf-8\r\n"; 

$headers .=  'from: '.$lp .'' . "\r\n" .

            'Reply-To: '.$lp.'' . "\r\n" .

            'X-Mailer: PHP/' . phpversion();

foreach($to as $row)
{
   mail($row,$subject,$message,$headers);
}

echo "Mail Sent.";
die;
?>

在共享主机上,您通常需要从“现有电子邮件”发送电子邮件,至少与域匹配。也许这就是为什么邮件没有被发送

例如,如果你的域名是“www.my-awesome-domain.com”,你就不能发送邮件头

"from: example@example.com"
相反,请确保从您的域发送电子邮件,最好是现有的邮箱,例如:

"from: office@my-awesome-domain.com"

希望有帮助!:)

你是说这段代码有效,但不是每个人都会收到电子邮件?你确定它不会只是在垃圾邮件/垃圾邮件文件夹中结束吗?首先,你的
$message=“注册详细信息如下:”-仅此一项就可以打破它。另外,请确保表单的元素确实是
name
'd。此外,您需要将此
$from=$\u POST['email']
$subject=“电子邮件通知”之前。如果不这样做,你就没有定义它。这有点像是本末倒置。我测试了你的代码,没有问题。确保他们没有以垃圾邮件结束,或者可能被你的服务器拒绝,或者被某些电子邮件服务(如Gmail、Yahoo等)列入黑名单。