我想从我网站的联系页面发送电子邮件。我谷歌和它告诉使用PHP脚本,因为我的域是基于LINUX,所以我不能使用ASP。我尝试了几个但不能发送。我怎么用@ECHO来显示消息,我收到的但不是电子邮件。这里是我尝试的代码:
<?php
$userid='to.useri@example.com';
$subject='New Requirement';
$Name=$_POST['Name'];
$Email=$_POST['Email'];
$Phone=$_POST['Phone'];
$Message=$_POST['Message'];
$body= <<<EOD;
<br><hr><br>
Name: $Name <br>
Email: $Email <br>
Phone: $From <br>
Message: $Message
EOD;
$headers='From: $Email';
mail($userid,$subject,$body,$headers);
echo "Message send!!!";
?>
我也尝试过:
<?php
$to = 'to.user@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: from.user@example.com' . "\r\n" .
'Reply-To: from.user@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers )) {
ECHO 'Message send successfully';
}
else {
ECHO 'Please try again, Message could not be sent!';
}
?>
任何人都可以告诉我这里缺少什么。
答案 0 :(得分:1)
使用下面提到的代码更改if条件,希望它有效: -
$mail=mail($to, "Subject: $subject",$message );
if($mail){
echo "Thank you for using our mail form";
}else{
echo "Mail sending failed.";
}
答案 1 :(得分:0)
试试这段代码
$senderName="John";
$senderEmail= "test@domain.com";
$recipient = "recipient@domain.com";
$subject ="testmail";
$message="test message";
$headers = "From: " . $senderName . " <" . $senderEmail . ">";
$success = mail($recipient, $subject, $message, $headers );