在php中发送电子邮件,邮件头出现问题


Sending Email in php, headers problems

我正在尝试使用mail()函数发送电子邮件。。。这是我的代码:

     <html>
     <form action ="" method ="post">
     <input type="submit" name= "email" value="email">
     <form>
     <?php
     if (isset($_POST['email']))
     {
     mail("receiver@hotmail.com", "Subject: Hi", "hello" );
     echo "Mail Sent";
     }
     ?> 
     </html>

关于的代码工作得很好,我可以收到电子邮件,但唯一的问题是当我检查电子邮件时,发件人会是"webmaster@something.org"

我试图将代码更改为:

     mail("receiver@hotmail.com", "Subject: Hi","hello", "From: sender@yahoo.com"  );

但没用。。。你能帮我把发邮件的人的名字写出来吗。。。非常感谢

请尝试一下。这是给某人发邮件最简单的方法。

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "'r'n" .
    'Reply-To: webmaster@example.com' . "'r'n" .
    'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

查看php邮件手册。您需要在标题中定义"From:xxx"

检查表单标记是否关闭?

<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

使用[phpmailer发送邮件。

您可以设置邮件的发件人id和内容类型。