I want to send email from contact page of the my site. I google and it told to use PHP scripts as my domain is LINUX based so I cannot use ASP. I tried couple of them but not able to send. How ever I have used @ECHO to display message, which I got but not the email. Here the codes that I tried:
我想从我网站的联系页面发送电子邮件。我谷歌和它告诉使用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!!!";
?>
And I also tried :
我也尝试过:
<?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!';
}
?>
Can any one tell me what am I missing here.
任何人都可以告诉我这里缺少什么。
2 个解决方案
#1
1
Change your if Condition with the below mentioned code, hope it works:-
使用下面提到的代码更改if条件,希望它有效: -
$mail=mail($to, "Subject: $subject",$message );
if($mail){
echo "Thank you for using our mail form";
}else{
echo "Mail sending failed.";
}
#2
0
try this code
试试这段代码
$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 );
#1
1
Change your if Condition with the below mentioned code, hope it works:-
使用下面提到的代码更改if条件,希望它有效: -
$mail=mail($to, "Subject: $subject",$message );
if($mail){
echo "Thank you for using our mail form";
}else{
echo "Mail sending failed.";
}
#2
0
try this code
试试这段代码
$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 );