我是php的初学者。 我正在尝试使用php发送邮件。 我的邮件发送到邮件客户端,但它没有像我想的那样显示标题部分。 我使用以下代码----
<?php
//validation expected data exists
if(!isset($_POST["name"]) ||
!isset($_POST["city"]) ||
!isset($_POST["email"]) ||
!isset($_POST["phone"]) ||
!isset($_POST["message"])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
//Subject
$name = $_POST["name"];
$subject = "NO REPLY";
$email = $_POST["city"];
$phone = $_POST["email"];
$website = $_POST["phone"];
$message = $_POST["message"];
$header = "from: $name <$email>";
$to = 'info@mishmihillsadventure.in';
$send_contact=mail($to,$subject,$message,$header);
//Check, if message sent to your email
// Display message "We've recived your information"
if($send_contact){
echo "We've received your contact information";
}
else{
echo "ERROR";
}
?>
答案 0 :(得分:1)
$email = $_POST["city"];
$phone = $_POST["email"];
这真的是你想要的吗?不应该是:
$email = $_POST["email"];
然后尝试以下标题:
$header = 'From: ' . $name . '<' . $email . '>' . "\r\n";
答案 1 :(得分:0)
通过PHP发送邮件时使用(最近)标题 -
$header = "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$header .= "From: $name <$email>" . "\r\n";
//If want to `CC` someone add
$header .= 'Cc: abc@email.com' . "\r\n";
在Double quotes
中使用变量很好。
答案 2 :(得分:0)
你可以尝试类似下面提到的代码,
<?php
$to = 'test@to.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: test@from.com' . "\r\n" .
'Reply-To: test@from.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)) {
echo 'Msg send..';
} else {
echo 'Msg Not send..';
}
?>