[英]Send mail from homepage. What am I missing in my code?
I would like to be able to send mail from my homepage but it aint working as I want. 我希望能够从我的主页发送邮件,但是它并不能按我的要求工作。 i get a mail but it doesnt say from home.
我收到邮件,但没有从家里说。 Just says Unknown.
只是说未知。 The thing I have this in two diffrent places.
我在两个不同的地方都有这个东西。 The other place I use other textareas and there I get everything in my mail and it works fine but this other place I am trying to work I only want them to add there email and then it should be sent with all info.
另一个地方我使用其他文本区域,在那里我可以收到邮件中的所有内容,并且可以正常工作,但是我试图在另一个地方工作,我只希望他们在此处添加电子邮件,然后将其与所有信息一起发送。
My code on my page: 我在页面上的代码:
<form id="subscribe" class="clearfix" method="post" action="get_mail.php">
<div class="field alignleft">
<input type="text" value="Enter your email" onclick="if(this.value=='Enter your email')this.value='';" onblur="if(this.value=='')this.value='Enter your email';" />
</div>
<div class="search-btn">
<input type="submit" value="" />
</div>
</form>
Then I have this php script 然后我有这个PHP脚本
<?php
//-----------------------------------------------------
//-----------------------------------------------------
$address= "xxxxx.xxxxx@outlook.com";
//-----------------------------------------------------
//-----------------------------------------------------
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$website = $_REQUEST["website"];
$subject .= "You have an email from your web site (from $name)! \n\n";
$message_content = strip_tags($_REQUEST["message"]);
$headers = "From: $name <$email>\n";
$headers .= "Reply-To: $subject <$email>\n";
$message = "--$mime_boundary\n\n";
$message .= "You have an email from your web site: \n\n\n";
$message .= "Name: $name \n\n";
$message .= "Email: $email \n\n";
$message .= "Website: $website \n\n";
$message .= "Message: $message_content \n\n";
$message .= "--$mime_boundary--\n\n";
$mail_sent = mail($address, $subject, $message, $headers);
echo $mail_sent ? "Success, mail sent!" : "Mail failed";
?>
Two things: 两件事情:
Try replacing "\\n" in $headers with "\\r\\n". 尝试将$ header中的“ \\ n”替换为“ \\ r \\ n”。
As far as I know, some hosts (I think GoDaddy or Hostgator do this for example) will override the "from" value in sent emails and change it to the one you have with them. 据我所知,某些主机(例如,我认为GoDaddy或Hostgator会这样做)将覆盖已发送电子邮件中的“ from”值,并将其更改为您与他们共享的电子邮件。 This means that if you don't explicitly have "from@domain.com" in your hosting account you won't be able to send emails from that address and it will be always overridden.
这意味着,如果您的托管帐户中没有明确包含“ from@domain.com”的内容,则您将无法从该地址发送电子邮件,并且该电子邮件将始终被覆盖。 You have to contact your host to check this.
您必须联系您的房东以进行检查。 I suggest also checking the script on another server if possible.
我建议还尽可能检查另一台服务器上的脚本。
None of your form fields appear to have names - your code here: 您的表单字段似乎都没有名称-您的代码在这里:
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$website = $_REQUEST["website"];
requires form fields with the names "name", "email", and "website". 需要名称为“ name”,“ email”和“ website”的表单字段。 For example, your "email" field needs to look like this:
例如,您的“电子邮件”字段需要如下所示:
<input type="text" name="email" ... />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.