有点奇怪的php邮件功能

时间:2015-01-15 05:41:34

标签: php email

错误地,我在邮件功能中添加了from-address as-address。   它发送邮件到地址和从地址为什么?是否记录在哪里?

$from = 'from_user@gmail.in';
$to = 'to_user@gmail.com';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $to  . "\r\n";
$headers .= 'From: ' . $from . "\r\n";

$message = json_encode(compact('to', 'from', 'headers'));

  // NOTE THE FROM INSTEAD OF TO
mail($from, $subject, $message, $headers);

1 个答案:

答案 0 :(得分:1)

继续评论并突出您的参考请求。这是一本来自php手册的snippit供参考。请注意第一行附加标题:

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

因此,您要通过mail($to...发送电子邮件(在您的案例中恰好是$from),但您也在$to中发送了$headers声明。