【问题标题】:Send the data of this form to a gmail account via php通过 php 将此表单的数据发送到 gmail 帐户
【发布时间】:2018-05-07 09:11:41
【问题描述】:

我想通过 php 将此表单中的数据发送到 gmail 帐户。现在,如果我发送它没有任何反应,请包含垃圾邮件文件夹。

    <label for="email" id="email">Email <span>*</span></label>
    <input type="email" id="" name="email">

     <div>
         <div>
            <label for="name" id="text">Nombre <span>*</span> </label>
            <input type="text" id="name" name="name">
         </div>
         <div>
            <label for="tlf-num">Teléfono <span>*</span> </label>
            <input id="tlf-num" type="text" name="tlf-num" >
        </div>
     </div>
    <div>
        <label for="message" id="#">Mensaje</label>
        <textarea contenteditable="false" name="message" id="message" cols="30" rows="10"></textarea>
    </div>
    <input type="submit" value="ENVIAR">
</form>

这是php,我不知道出了什么问题。这段代码大约三年前在其他网站上为我工作。我读到了电子邮件标题和 gmail 风格的帐户,它们在 recibe 上存在问题,但我不知道。我对发生的事情感到有些困惑。

<?php

if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['tlf-   num']) && isset($_POST['message']) != ""){

$nombre = $_POST['name'];
$mail = $_POST['email'];
$header = 'From: ' . $mail . " \r\n";
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/plain";
$mensaje = "Nombre " . $nombre . " ";
$mensaje .= "Su e-mail es: " . $mail . " \r\n";
$mensaje .= "Mensaje: " . $_POST['message'] . " \r\n";
$mensaje .= "Enviado el " . date('d/m/Y', time());
$para = 'loquesea@gmail.com';
$asunto = 'Formulario contacto Web';

mail($para, $asunto, utf8_decode($mensaje), $header);
echo "<script type='text/javascript'>
    setTimeout( function() {
      window.location.href='https://loquesea.com';
    }, 1500)
     </script>";
}
else{
    echo "<script type='text/javascript'>
        alert('Revisa los datos');
        window.location.href='https://loquesea.com';
 </script>";
}

?>

我在第一个答案后检查了我的 php.ini 文件并进行了此配置,可能需要更改某些内容或添加任何选项或其他内容?。

[mail function]
; For Win32 only.
; http://php.net/smtp
; SMTP = localhost
; http://php.net/smtp-port
; smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path = "env -i /usr/sbin/sendmail -t -i"

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail().
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On

; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on Windows).
;mail.log = syslog

【问题讨论】:

    标签: php forms gmail send


    【解决方案1】:

    请检查您的 php.ini 文件以了解邮件设置。 mail() 函数使用 .ini 文件中设置的参数发送邮件。

    对于 Ubuntu:

    安装发送邮件

    sudo apt-get install sendmail
    

    在此处配置您的主机

    sudo vim /etc/hosts
    

    (这里的文本编辑器是 Vim)

    保存并运行 sendmail 的配置

    sudo sendmailconfig
    

    最后,重启 Apache

    sudo service apache2 restart
    

    更多详情请参考this链接

    【讨论】:

    • 我在问题中添加了我在 php.ini 中的邮件功能
    • 您使用的是哪个操作系统?
    • 操作系统是Ubuntu
    猜你喜欢
    • 2013-04-07
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 2023-02-19
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多