簡體   English   中英

通過php發送此表格的數據到Gmail帳戶

[英]Send the data of this form to a gmail account via php

我想通過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樣式帳戶的信息,這些帳戶在收據上會出現問題,但我不知道。 我對發生的事情感到有些困惑。

<?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.ini文件中的郵件設置。 mail()函數使用.ini文件中設置的參數發送郵件。

對於Ubuntu:

安裝sendmail

sudo apt-get install sendmail

在這里配置主機

sudo vim /etc/hosts

(Vim是此處的文本編輯器)

保存並運行sendmail的配置

sudo sendmailconfig

最后,重啟Apache

sudo service apache2 restart

請參閱鏈接以獲取更多詳細信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM