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

时间:2022-11-10 22:21:53

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.

我希望能够从我的主页发送邮件,但它不能按我的意愿工作。我收到了一封邮件,但它并没有在家里说。只是说未知。我在两个不同的地方有这个。另一个地方,我使用其他textareas,在那里我得到了我的邮件中的一切,它工作正常,但我正在尝试工作的其他地方我只希望他们添加电子邮件,然后它应该与所有信息一起发送。

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";

?>

2 个解决方案

#1


3  

Two things:

  1. Try replacing "\n" in $headers with "\r\n".

    尝试使用“\ r \ n”替换$ headers中的“\ 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. 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. You have to contact your host to check this. I suggest also checking the script on another server if possible.

    据我所知,一些主机(我认为GoDaddy或Hostgator这样做)会覆盖已发送电子邮件中的“起始”值,并将其更改为您拥有的电子邮件。这意味着,如果您未在主机帐户中明确地使用“from@domain.com”,则无法从该地址发送电子邮件,并且将始终覆盖该电子邮件。您必须联系您的主机进行检查。我建议如果可能的话也检查另一台服务器上的脚本。

#2


2  

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". For example, your "email" field needs to look like this:

需要名称为“name”,“email”和“website”的表单字段。例如,您的“电子邮件”字段需要如下所示:

<input type="text" name="email" ... />

#1


3  

Two things:

  1. Try replacing "\n" in $headers with "\r\n".

    尝试使用“\ r \ n”替换$ headers中的“\ 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. 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. You have to contact your host to check this. I suggest also checking the script on another server if possible.

    据我所知,一些主机(我认为GoDaddy或Hostgator这样做)会覆盖已发送电子邮件中的“起始”值,并将其更改为您拥有的电子邮件。这意味着,如果您未在主机帐户中明确地使用“from@domain.com”,则无法从该地址发送电子邮件,并且将始终覆盖该电子邮件。您必须联系您的主机进行检查。我建议如果可能的话也检查另一台服务器上的脚本。

#2


2  

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". For example, your "email" field needs to look like this:

需要名称为“name”,“email”和“website”的表单字段。例如,您的“电子邮件”字段需要如下所示:

<input type="text" name="email" ... />