简体   繁体   English

从首页发送邮件。 我的代码中缺少什么?

[英]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: 两件事情:

  1. Try replacing "\\n" in $headers with "\\r\\n". 尝试将$ header中的“ \\ n”替换为“ \\ r \\ n”。

  2. 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.

相关问题 我的搜索表单正在重定向到主页。 怎么解决? - My search form is redirecting to the homepage. How to solve? 我在PHP代码中缺少什么来生成链接? - what i am missing in my php code to generate link? 我无法删除留在主页上的消息,以便从我的消息数据库和主页本身中删除 - I am unable to delete messages left on my homepage to delete from my messages db and the homepage itself SMTP connect()失败…当我尝试从我的php文件发送邮件时 - SMTP connect() failed… while i am trying to send mail from my php file 我的JQM表单上缺少什么? - What am I missing on my JQM Form? 我的C#到PHP代码转换中没有sha1匹配项,我缺少什么? - Not getting a sha1 match in my C# to PHP code conversion, what am I missing? Symfony 项目仅适用于主页。 当我导航到其他页面时,Apache 返回 404 - Symfony project works only homepage. When I navigate to the other pages Apache returns 404 无法发送会话缓存限制器,我缺少什么? - Cannot send session cache limiter, what am i missing? 将邮件发送到自己的域时会发生什么情况? - What's happening when I send to my own domain a mail? 我的WHILE循环从mysql表显示视频不起作用。 我想念什么? - My WHILE loop to display videos from mysql table is not working. What am I missing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM