我无法在php中为地址设置标题我尝试了所有可能的值:
以下代码是正确的,但代码未附加到标题。
它显示为默认值,但不会更改。
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);
答案 0 :(得分: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>");
}