2

我无法在 php 中为 from 地址设置标题我已经尝试了所有可能的值:

下面的代码是正确的,但代码未附加到 header 。

它将此显示为默认值,但不会更改。

From :  webhost:cpanel@hosting

这是 cpanel 的问题吗?

请帮助我非常感谢您的帮助。

提前致谢。

<?php

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['contact'];

$subject = "feedback";
$question = $_REQUEST['question'];


$body = "<html>
<head>

</html>";
$mime_boundary = "<<<--==+X[".md5(time())."]\r\n\r\n";
$headers = "MIME-Version: 1.0"."\r\n" ."Content-Type:text/html;"."\r\n";
$headers .= 'From:'.$email. "\r\n";


$to ='example@example.com';
mail($to,$subject,$body,$headers);
echo "<script>alert(' message  sent.');</script>";

?>

也试过:

<?php
$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: Sender Name <sender@domain.com>";
   $headers[] = "Reply-To: Recipient Name <receiver@domain3.com>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();

mail($to, $subject, $email, implode("\r\n", $headers));
?>

只有这个有效:

    $to ='example@example.com';
$subject="subject";
$body="body";
    $mime_boundary = "<<<--==+X[".md5(time())."]\r\n\r\n";
    $headers = "MIME-Version: 1.0"."\r\n" ."Content-Type:text/html;"."\r\n";
    mail($to,$subject,$body,$headers);
4

1 回答 1

2

尝试这个 :

$to = 'me@gmail.com';

$subject = "Email from me by: John";
$body = "my body";
$headers = "From: "."hello@world.com"."\r\n" .
"Reply-To: "."hello@world.com"."\r\n".
 "X-Mailer: php";
 $sent=mail($to, $subject, $body, $headers);

if ($sent) {

 echo "good!";

} else {
echo("<p>Message delivery failed...</p>");
}
于 2013-04-24T20:49:07.173 回答