如何使用ECSS和PHP发送电子邮件

如何使用ECSS和PHP发送电子邮件,php,html,materialize,Php,Html,Materialize,谢谢你阅读这篇文章, 我真的是一个编程初学者,我需要一些帮助,在一个简单的网站,我试图使。 我的目标是创建一个表单,向我发送邮件,但当我按send时,它只会将我发送回页面顶部。我在下面粘贴HTML和php。我要问你们的另一个问题是,我是否必须在我的web托管服务(ovh)上设置一些东西才能让php工作?谢谢大家,再见:) html: <form class="col s12"> <div class="row"> <div class="input-fi

谢谢你阅读这篇文章, 我真的是一个编程初学者,我需要一些帮助,在一个简单的网站,我试图使。 我的目标是创建一个表单,向我发送邮件,但当我按send时,它只会将我发送回页面顶部。我在下面粘贴HTML和php。我要问你们的另一个问题是,我是否必须在我的web托管服务(ovh)上设置一些东西才能让php工作?谢谢大家,再见:)

html:

<form class="col s12">
  <div class="row">
    <div class="input-field col s6">
      <i class="material-icons prefix">info</i>
      <input id="first_name" type="text" class="validate">
      <label for="first_name">Prénom</label>
    </div>
    <div class="input-field col s6">
      <i class="material-icons prefix">info</i>
      <input id="last_name" type="text" class="validate">
      <label for="last_name">Nom de famille</label>
    </div>
  </div>
  <div class="row">
    <div class="input-field col s12">
      <i class="material-icons prefix">phone</i>
      <input id="Mail" type="email" class="validate">
      <label for="Mail">E-mail</label>
    </div>
  </div>
    <div class="row">
        <form class="col s12">
        <div class="row">
            <div class="input-field col s12">
            <i class="material-icons prefix">chat</i>
            <textarea id="message" class="materialize-textarea"></textarea>
            <label for="message">Message</label>
            </div>
        </div>
<button class="btn waves-effect waves-light" type="submit" 
name="action">Envoyer
<i class="material-icons right">send</i>
</button>
        </form>

信息
名词
信息
家名
电话
电子邮件
聊天
消息
特使
发送
PHP:


我们开始得很慢,这里有一些错误提交表单是一个与客户端和服务器端的特殊对话框在这种情况下,服务器端PHP,表单标记首先需要使用发送数据so或POST或GET的方法,但您必须在html表单标记中看到这一点…因此您的html表单开始标记成为

<form class="col s12" method="post">
另外,因为是一个错误,所以必须使用html名称$\u POST['action'],并且必须在POST中写入$\u POST

 $from = $_POST['Mail'];
 $first_name = $_POST['first_name'];
 $last_name = $_POST['last_name'];

AHHH和IMHO建议最好使用input type=“submit”

我们开始得很慢,这里有一些错误提交表单是与客户端和服务器端的一个特殊对话框,在这种情况下,服务器端PHP,表单标签首先需要您想要用来发送数据的方法,所以,POST或GET,但您必须在html表单标签中看到这一点……因此,您的html表单开始标签成为

<form class="col s12" method="post">
另外,因为是一个错误,所以必须使用html名称$\u POST['action'],并且必须在POST中写入$\u POST

 $from = $_POST['Mail'];
 $first_name = $_POST['first_name'];
 $last_name = $_POST['last_name'];

AHHH和IMHO建议最好使用input type=“submit”

您必须定义表单操作,当按钮单击要执行的php脚本时,显然要发送邮件,您的服务器或主机确实需要一些配置

<form action="thephpfilename.php">

</form>

您必须定义表单操作,当按钮单击要执行的php脚本时,显然要发送邮件,您的服务器或主机确实需要一些配置

<form action="thephpfilename.php">

</form>

通过
PHPMailer发送电子邮件的简单易行的方法
最佳选择


看看这个

通过
PHPMailer
最佳选项发送电子邮件的简便方法


看看这个

谢谢大家帮助初学者,谢谢。 我根据您的说明和web教程对代码进行了一些修改,但现在发送了一封邮件,但它完全是emtpy,似乎我的变量是空的。谢谢

index.html

<form class="col s12" method="POST" action="mail.php">
  <div class="row">
    <div class="input-field col s6">
      <i class="material-icons prefix">info</i>
      <input id="first_name" type="text" class="validate" name="first_name">
      <label for="first_name">Prénom</label>
    </div>
    <div class="input-field col s6">
      <i class="material-icons prefix">info</i>
      <input id="last_name" type="text" class="validate" name="last_name">
      <label for="last_name">Nom de famille</label>
    </div>
  </div>
  <div class="row">
    <div class="input-field col s12">
      <i class="material-icons prefix">phone</i>
      <input id="mail" type="email" class="validate" name="email">
      <label for="mail">E-mail</label>
    </div>
  </div>
    <div class="row">
            <div class="input-field col s12">
            <i class="material-icons prefix">chat</i>
            <textarea id="message" class="materialize-textarea"></textarea>
            <label for="message">Message</label>
            </div>
  <button class="btn waves-effect waves-light" type="submit" name="action" id="submit" for="submit">Envoyer
<i class="material-icons right">send</i>
  </button>
    </div>
</form>

信息
名词
信息
家名
电话
电子邮件
聊天
消息
特使
发送
mail.php

<?php
error_reporting(E_ALL);
// if (isset($_POST['submit'])) {  <<-- not an error, I just wanted to get rid of it w/o deleting it
$prenom = !empty($_POST['first_name']) ? $_POST['first_name'] : NULL;
$nom = !empty($_POST['last_name']) ? $_POST['last_name'] : NULL;
$from = !empty($_POST['mail']) ? $_POST['mail'] : NULL;
$msg = !empty($_POST['message']) ? $_POST['message'] : NULL;

if(mail('hugoleon2002@gmail.com', 'Commande Amarrex', $msg))
{
     echo 'Le message a été envoyé';
}
else
{
     echo 'Le message n\'a pu être envoyé';
}
// }
?>

感谢大家帮助初学者,非常感谢。 我根据您的说明和web教程对代码进行了一些修改,但现在发送了一封邮件,但它完全是emtpy,似乎我的变量是空的。谢谢

index.html

<form class="col s12" method="POST" action="mail.php">
  <div class="row">
    <div class="input-field col s6">
      <i class="material-icons prefix">info</i>
      <input id="first_name" type="text" class="validate" name="first_name">
      <label for="first_name">Prénom</label>
    </div>
    <div class="input-field col s6">
      <i class="material-icons prefix">info</i>
      <input id="last_name" type="text" class="validate" name="last_name">
      <label for="last_name">Nom de famille</label>
    </div>
  </div>
  <div class="row">
    <div class="input-field col s12">
      <i class="material-icons prefix">phone</i>
      <input id="mail" type="email" class="validate" name="email">
      <label for="mail">E-mail</label>
    </div>
  </div>
    <div class="row">
            <div class="input-field col s12">
            <i class="material-icons prefix">chat</i>
            <textarea id="message" class="materialize-textarea"></textarea>
            <label for="message">Message</label>
            </div>
  <button class="btn waves-effect waves-light" type="submit" name="action" id="submit" for="submit">Envoyer
<i class="material-icons right">send</i>
  </button>
    </div>
</form>

信息
名词
信息
家名
电话
电子邮件
聊天
消息
特使
发送
mail.php

<?php
error_reporting(E_ALL);
// if (isset($_POST['submit'])) {  <<-- not an error, I just wanted to get rid of it w/o deleting it
$prenom = !empty($_POST['first_name']) ? $_POST['first_name'] : NULL;
$nom = !empty($_POST['last_name']) ? $_POST['last_name'] : NULL;
$from = !empty($_POST['mail']) ? $_POST['mail'] : NULL;
$msg = !empty($_POST['message']) ? $_POST['message'] : NULL;

if(mail('hugoleon2002@gmail.com', 'Commande Amarrex', $msg))
{
     echo 'Le message a été envoyé';
}
else
{
     echo 'Le message n\'a pu être envoyé';
}
// }
?>

我终于回答了我自己的问题,谢谢你的时间和帮助:) 再见

index.html:

<form class="col s12" method="POST" action="mail.php">
  <div class="row">
    <div class="input-field col s6">
      <i class="material-icons prefix">info</i>
      <input id="first_name" type="text" class="validate" name="first_name">
      <label for="first_name">Prénom</label>
    </div>
    <div class="input-field col s6">
      <i class="material-icons prefix">info</i>
      <input id="last_name" type="text" class="validate" name="last_name">
      <label for="last_name">Nom de famille</label>
    </div>
  </div>
  <div class="row">
    <div class="input-field col s6">
      <i class="material-icons prefix">mail</i>
      <input id="mail" type="email" class="validate" name="email">
      <label for="mail">E-mail</label>
    </div>
    <div class="input-field col s6">
      <i class="material-icons prefix">phone</i>
      <input id="phone" type="tel" name="phone">
      <label for="phone">Téléphone (optionel)</label>
    </div>
  </div>
    <div class="row">
            <div class="input-field col s12">
            <i class="material-icons prefix">chat</i>
            <textarea id="message" class="materialize-textarea" name="message"></textarea>
            <label for="message">Message</label>
            </div>
<button class="btn waves-effect waves-light" type="submit" name="action" id="submit" for="submit">Envoyer
<i class="material-icons right">send</i>
</button>
    </div>
</form>

信息
名词
信息
家名
邮件
电子邮件
电话
Téléphone(可选)
聊天
消息
特使
发送
mail.php:

<?php
$prenom = !empty($_POST['first_name']) ? $_POST['first_name'] : NULL;
$nom = !empty($_POST['last_name']) ? $_POST['last_name'] : NULL;
$from = !empty($_POST['email']) ? $_POST['email'] : NULL;
$msg = !empty($_POST['message']) ? $_POST['message'] : NULL;
$tel = !empty($_POST['phone']) ? $_POST['phone'] : NULL;
$headers = 'From: WEBSITE E-MAIL';
//  echo "$msg" . "$nom" . "$from";

if(empty($prenom) || empty($nom) || empty($from) || empty($msg)) 
{
     echo 'Mail couldn't be send, a fiel is empty';
}
elseif(mail('EMAIL ADRESS', "Commande Amarrex de $prenom $nom", "$prenom $nom a ecrit : $msg \n\n\n E-mail de contact : $from\n\n Telephone : $tel", "$headers"))
{
     echo 'Mail sent.';
}
else
{
    echo 'mail not sent, unexpected error';
}
// }
?>

我终于回答了我自己的问题,谢谢你的时间和帮助:)
再见

index.html:

<form class="col s12" method="POST" action="mail.php">
  <div class="row">
    <div class="input-field col s6">
      <i class="material-icons prefix">info</i>
      <input id="first_name" type="text" class="validate" name="first_name">
      <label for="first_name">Prénom</label>
    </div>
    <div class="input-field col s6">
      <i class="material-icons prefix">info</i>
      <input id="last_name" type="text" class="validate" name="last_name">
      <label for="last_name">Nom de famille</label>
    </div>
  </div>
  <div class="row">
    <div class="input-field col s6">
      <i class="material-icons prefix">mail</i>
      <input id="mail" type="email" class="validate" name="email">
      <label for="mail">E-mail</label>
    </div>
    <div class="input-field col s6">
      <i class="material-icons prefix">phone</i>
      <input id="phone" type="tel" name="phone">
      <label for="phone">Téléphone (optionel)</label>
    </div>
  </div>
    <div class="row">
            <div class="input-field col s12">
            <i class="material-icons prefix">chat</i>
            <textarea id="message" class="materialize-textarea" name="message"></textarea>
            <label for="message">Message</label>
            </div>
<button class="btn waves-effect waves-light" type="submit" name="action" id="submit" for="submit">Envoyer
<i class="material-icons right">send</i>
</button>
    </div>
</form>

信息
名词
信息
家名
邮件
电子邮件
电话
Téléphone(可选)
聊天
消息
特使
发送
mail.php:

<?php
$prenom = !empty($_POST['first_name']) ? $_POST['first_name'] : NULL;
$nom = !empty($_POST['last_name']) ? $_POST['last_name'] : NULL;
$from = !empty($_POST['email']) ? $_POST['email'] : NULL;
$msg = !empty($_POST['message']) ? $_POST['message'] : NULL;
$tel = !empty($_POST['phone']) ? $_POST['phone'] : NULL;
$headers = 'From: WEBSITE E-MAIL';
//  echo "$msg" . "$nom" . "$from";

if(empty($prenom) || empty($nom) || empty($from) || empty($msg)) 
{
     echo 'Mail couldn't be send, a fiel is empty';
}
elseif(mail('EMAIL ADRESS', "Commande Amarrex de $prenom $nom", "$prenom $nom a ecrit : $msg \n\n\n E-mail de contact : $from\n\n Telephone : $tel", "$headers"))
{
     echo 'Mail sent.';
}
else
{
    echo 'mail not sent, unexpected error';
}
// }
?>

只在live server上发送电子邮件,即您的网站必须托管,然后再尝试。否则它就不会像hostgator或其他人那样工作。你试过了吗?只在live server上发送电子邮件,即你的网站必须托管,然后再尝试。否则它就不会像hostgator或其他人那样工作。你试过了吗?