簡體   English   中英

PHP形式-Godaddy經濟托管Linux

[英]php form - godaddy economic hosting Linux

我有這種形式:

<form action="/sendemail.php" id="main-contact-form" method="post" name="contact-form" role="form">
<div class="form-group">
    <input class="form-control" id="name" name="name" placeholder="put your name" required="" type="text" />
</div>

<div class="form-group">
    <input class="form-control" id="email" name="email" placeholder="Email" required="" type="email" />
</div>

<div class="form-group">
    <input class="form-control" id="subject" name="subject" placeholder="Subject..." required="" type="text" />
</div>

<div class="form-group">
    <textarea class="form-control" name="message" placeholder="Mensaje" required="" rows="8"></textarea>
</div>

<input class="btn btn-primary" id="submit" name="submit" type="submit" value="Enviar" />

這是sendemail.php:

<?php
        $pos = $_POST;
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $from = $_POST['email']; 
        $to = 'email@gmail.com '; 
        $subject = 'contact message ';

        $body = "From: $name\n E-Mail: $email\n Message:\n $message\n $pos";




    mail ($to, $subject, $body, $from)



?>

電子郵件是空的,我嘗試了很多東西,但是總是以相同的方式發送,就像表單無法將數據從輸入傳遞到php變量一樣。 我是php中的新手,歡迎任何幫助。

謝謝。

更新
經過研究,我發現:

您需要詢問godaddy技術支持以啟用“ sendmail”。

PHP mail()在GoDaddy上不起作用

----------

我已經測試了您的代碼,並且可以正常工作 我已經收到包含所有 $_POST內容的電子郵件,沒有任何問題。

$pos = $_POST;
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = $_POST['email']; 
$to = 'email@gmail.com '; 
$subject = 'contact message ';

注意:

1- $pos = $_POST; 是一個array ,它將顯示為Array
2-通過mail()發送的mail()很可能最終會出現在垃圾郵件文件夾中 (請閱讀下面的評論)。

mail()函數的使用是如此不安全,並且是發送大量垃圾郵件的媒介攻擊,請不要再使用了,因此最好使用PHP Mailer libray。

在托管中創建一個EMAIL帳戶(例如:no-reply@domain.com),然后安裝該庫PHP Mailer ,現在您可以執行以下操作:

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$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';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

暫無
暫無

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

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