Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
I';m:如何使用PHP邮件发送HTML表单_Php_Html_Xampp_Localhost_Phpmailer - Fatal编程技术网

I';m:如何使用PHP邮件发送HTML表单

I';m:如何使用PHP邮件发送HTML表单,php,html,xampp,localhost,phpmailer,Php,Html,Xampp,Localhost,Phpmailer,好的,所以我在过去几天里做了大量的研究,我被难倒了。我有XAMPP和PHP Mailer,我知道它们在本地都能正常工作 我还有一个HTML表单,我知道它在使用Hostgator web托管时工作正常。此HTML表单调用名为send_email.php的.php文件,该文件将表单内容发送到我的电子邮件 我的问题是: 使用PHPMailer在我的本地主机(XAMPP)上发送这个HTML表单的新的.php代码(粗略地说)是什么 如何在HTML文件中调用新的.php文件 对于这个HTML表单和php M

好的,所以我在过去几天里做了大量的研究,我被难倒了。我有XAMPP和PHP Mailer,我知道它们在本地都能正常工作

我还有一个HTML表单,我知道它在使用Hostgator web托管时工作正常。此HTML表单调用名为send_email.php的.php文件,该文件将表单内容发送到我的电子邮件

我的问题是:

  • 使用PHPMailer在我的本地主机(XAMPP)上发送这个HTML表单的新的.php代码(粗略地说)是什么
  • 如何在HTML文件中调用新的.php文件
  • 对于这个HTML表单和php Mailer用来发送它的新的.php文件,我需要什么样的文件树结构
  • 请注意:我更改了代码中的一些详细信息,因此我没有包括我的实际电子邮件地址和个人信息

    这是我的表格:

    <!-- THE SUBMISSION FORM -->
    <div class="container">  
    
              <form id="contact" action="send_email.php" method="post">
    
                  <h3>Apply Today!</h3>
                  <h4></h4>
    
                  <fieldset>
                      <input placeholder="Full Name" type="text" name="name" tabindex="1" required autofocus>
                  </fieldset>
    
                  <fieldset>
                      <input placeholder="Telephone Number" type="tel" name="telephone" tabindex="2" required>
                  </fieldset>
    
                  <fieldset>
                      <input placeholder="Email Address" type="email" name="email" tabindex="3" required>
                  </fieldset>
    
                  <fieldset>
                      <input placeholder="Subject" type="text" name="subject" tabindex="4" required>
                  </fieldset>
               
                  <fieldset>
                      <textarea placeholder="Type your Message Here...." name="message" tabindex="5" required></textarea>
                  </fieldset>
                
                  <fieldset>
                      <button name="submit" type="submit" id="contact-submit" data-submit="...Sending" tabindex="6">Submit</button>
                  </fieldset>
    
              </form> 
    
    </div>
    
    
    今天就申请!
    提交
    
    这是我正在使用的send_email.php文件(我知道该文件有效)


    您根本不必更改代码;无论从何处运行,它都应该同样有效。只要您使用的是主机提供商允许的发送机制,例如,他们不阻止出站SMTP,它就可以正常工作。你试过了吗

    除此之外,您的文件结构看起来有点不寻常。Composer为您安装PHPMailer,并在您请求时自动加载它,所以Composer还负责它的存储位置;您不需要创建自己的
    phpmailer
    文件夹。如果您只托管一个站点,可能不需要将内容放在web根目录的子文件夹中,因此您可以使用更平坦的结构,如:

    c:/Users/dylan/.bitnami/stackman/machines/xampp/volumes/root/htdocs/
        index.php
        send_email.php
        vendor/
            composer/
            phpmailer
    

    如果您托管多个站点,您通常会在
    ../htdocs/
    中有多个文件夹,每个文件夹都具有类似的内部结构。

    您对php没有任何知识。

  • 首先,当您使用.php文件时,可以在其中使用html
  • 你认为这是个玩笑吗?
  • 你需要设置它

  • 整个代码都错了

    进入主页”; 邮件($to、$subject、$message、$headers); 邮件($to2,$subject,$message,$headers); 邮件($to3,$subject,$message,$headers); }否则{ echo“您必须写一条消息,请转到主页”; } ?>
  • 最后一个 这是我在XAMPP上的PHP Mailer位置:

    c:/Users/dylan/.bitnami/stackman/machines/xampp/volumes/root/htdocs/phpmailer

    这是我的HTML表单和send_email.php的位置:

    c:/Users/dylan/.bitnami/stackman/machines/xampp/volumes/root/htdocs/WEBSITE

    您将PHPMAILER放在您网页的目录中!!!!!!!1
    
    try {
        //Server settings
        $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
        $mail->isSMTP();                                            //Send using SMTP
        $mail->Host       = 'smtp.gmail.com';                     //Set the SMTP server to send through
        //$mail->Host = gethostbyname('smtp.gmail.com');
        $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
        $mail->Username   = 'sender@gmail.com';                     //SMTP username
        $mail->Password   = 'sender-password';                               //SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged                                   //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
        $mail->Port       = 587;                                    //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
    
        //Recipients
        $mail->setFrom('receiver1@gmail.com', 'Mailer');
        $mail->addAddress('receiver2@gmail.com', 'Dylan');     
    
        //Content
        $mail->isHTML(true);                                  //Set email format to HTML
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    
        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }
    
    
    $mail->setFrom('receiver1@gmail.com', 'Mailer');
    $mail->addAddress('receiver2@gmail.com', 'Dylan');