简体   繁体   English

使用域服务器 email 和 PHP 发送 email

[英]Send email using domain server email with PHP

.hi guys can anyone guide me on how to create a PHP form that sends an email to a desired recipient using the email provided by my domain server.大家好,任何人都可以指导我如何创建一个 PHP 表单,该表单使用我的域服务器提供的 email 将 email 发送给所需的收件人。

<?php

if($_POST['submit'])
{
    $name = $_POST['name'];
    $message = $_POST['message'];

    if($name&&$message)
    {
        $namelen = 20;
        $messagelen = 300;
        if(strlen($name)<=$namelen&&strlen($message)<=$messagelen)
        {
            $to = "myemail@yahoo.com";
            $subject = "Test Email";
            $headers = "From: my server provided email here";

            ini_set("SMTP", "/*i placed my domain server here");

            $body = "This is an email from $name\n\n$message";

            mail($to, $subject, $body, $headers);
            die();
        }
        else
        die("Max length for name is $namelen, and max length for message is $messagelen.");
    }
    else
    die("You must enter a name <u>and</u> message");
    /*echo $name.' '.$message;*/
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action='mailpush.php' method='POST'>
    Name:<input type='text' name='name' maxlength='20'><br>
    Message:<br /><textarea name='message'></textarea><p>
    <input type='submit' name='submit' value='Send me this'></p>
</form>
</body>
</html>

.this is the code i have so far. .这是我到目前为止的代码。 but when i try to send i don't receive anything.但是当我尝试发送时,我什么也没收到。

when i try to send i don't receive anything当我尝试发送时,我没有收到任何东西

So really your problem is not in writing the code, but in diagnosing why it's failing.所以实际上你的问题不在于编写代码,而在于诊断它失败的原因。

First thing of note is that you don't check the return value of the mail() call.首先要注意的是,您没有检查 mail() 调用的返回值。

ini_set("SMTP", "/*i placed my domain server here"); ini_set("SMTP", "/*我把我的域服务器放在这里");

What is this supposed to mean?这是什么意思? There is no such thing as a "domain server".没有“域服务器”之类的东西。 There are domain name servers, SMB domain masters, SMTP servers.....有域名服务器、SMB域主、SMTP服务器......

Next, you've provided no details of the OS this is running on nor the config for mail in php.ini: although you're explicitly setting the SMTP host (to what?, is it resolvable?) what is the setting for smtp_port?接下来,您没有提供正在运行的操作系统的详细信息,也没有提供 php.ini 中的邮件配置:尽管您明确设置了 SMTP 主机(设置为什么?,它是否可解析?) smtp_port 的设置是什么? Can you telnet to that port on the named machine from where the PHP code is running?您可以远程登录到运行 PHP 代码的命名机器上的那个端口吗?

There are an awful lot of technology things between your code and your mailbox - many of which could cause problems with the mail delivery - have you looked at these?在你的代码和邮箱之间有很多技术问题——其中许多可能导致邮件传递问题——你看过这些吗? Your local SMTP server is just the next hop in the chain, did you check if your email was enqueued there?您本地的 SMTP 服务器只是链中的下一跳,您是否检查过您的 email 是否在那里排队? If it was, then its nothing to do with PHP.如果是,那么它与 PHP 无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM