第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP Mailer 沒有顯示錯誤但不發(fā)送電子郵件

PHP Mailer 沒有顯示錯誤但不發(fā)送電子郵件

PHP
手掌心 2022-01-02 15:45:01
我正在創(chuàng)建一個預訂表格作為幫助,但已決定通過域而不是服務器發(fā)送郵件。這主要是為了更好的安全性和更少的響應和數(shù)據(jù)傳輸限制。最近幾天我一直在研究這個,并試圖自學如何讓它發(fā)揮作用。我現(xiàn)在有一個非常簡單的工作示例,可以在下面看到。這是簡單的預訂表格:<form method="post" name="process.php" action="process.php"><p>Name:</p><br><input type="text" name="name"><br><br><p>Email Address:</p><br><input type="email" name="email"><br><br><br><input type="submit" name="submit" value="Send Email">然后在process.php我有這個工作代碼:<?phpuse PHPMailer\PHPMailer\PHPMailer;if(isset($_POST['submit'])) {    // Values need to be santiised    $name = $_POST['name']; //Name of the person requesting a booking    $email = $_POST['email']; //Email of the person requesting a booking        require '../vendor/autoload.php';    $mail = new PHPMailer;    $mail->isSMTP();    $mail->SMTPDebug = 0;    $mail->Host = 'smtp.hostinger.com';    $mail->Port = 587;    $mail->SMTPAuth = true;    $mail->Username = 'test@handler.net';    $mail->Password = '[PASSWORD]';    $mail->setFrom('test@handler.net'); // All emails would be sent from the handler.net domain to the bookings email of the other domain. (Using test to test, will be noreply)    $mail->addAddress('bookings@salon.com'); // Recipient of the email should be the bookings address, this won't change.    $mail->addReplyTo($email); // The reply to address will be the email address of the user who submitted the booking enquiry.    if(!$mail->send()) { // Send the email.      echo 'Message was not sent.';      echo 'Mailer error: ' . $mail->ErrorInfo;    } else {      echo 'Message has been sent.';    }}?>上面的代碼有效并將電子郵件從正確的地址發(fā)送到正確的地址。那是在一個站點上public_html/testing并且已被移動到另一個站點中,public_html/booking因此相對路徑將是相同的。此目錄中的唯一文件是index.php(表單)和send.php(帶有確認消息的流程文件)出于某種原因,這個包含所有表單值的新代碼將不會發(fā)送。老實說,我不太確定為什么它現(xiàn)在不起作用,因此將非常感謝任何指針。
查看完整描述

3 回答

?
HUX布斯

TA貢獻1876條經(jīng)驗 獲得超6個贊

您應該查看$mail->addAdress,$mail->addBCC和$mail->addReplyTo字段并遵循這些字段的正確語法。


測試下面的代碼。


    <?php


    use PHPMailer\PHPMailer\PHPMailer;


    if(isset($_POST['submit'])) 

    {

        // Values need to be santiised


        $forename = $_POST['forename'];

        $surname = $_POST['surname'];

        $email = $_POST['email'];

        $phone = $_POST['phone'];

        $service = $_POST['service'];

        $date = $_POST['date'];

        $time = $_POST['time'];


        require '../vendor/autoload.php';


        $mail = new PHPMailer;

        $mail->isSMTP();

        $mail->SMTPDebug = 0;

        $mail->Host = 'smtp.hostinger.com';

        $mail->Port = 587;

        $mail->SMTPAuth = true;

        $mail->Username = 'test@handler.net';

        $mail->Password = '[PASSWORD]';


        $mail->setFrom('test@handler.net','Bookings'); // Emails sent via Noreply.


        $mail->addAddress('bookings@salon.com',''); // Email form responses sent to bookings@salon.com


        $mail->addReplyTo($email,$forename.' '.$surname); // Reply to the user who submitted the form.


        $mail->addBCC('outbox@handler.net',''); // Store record of all emails sent via the system.


        $mail->Subject = 'Booking Request'; // Subject of the email sent to admin@handler.net that the form responses will be contained within.


        $mail->isHTML(TRUE);

        $mail->Body = <<<EOD

            Booking request from {$forename} with email {$email}.<br  />

            Contact details: <br />

            Full name: {$forename} {$surname}<br />

            Email: {$email} <br />

            Phone number: {$phone} <br />

            Service: {$service} <br />

            Date: {$date} {$time}

EOD;

        if(!$mail->send()) { // Send the email.

          echo '';

          echo 'Mailer error: ' . $mail->ErrorInfo;

        } else {

          echo '';

        }

    }

    ?>


查看完整回答
反對 回復 2022-01-02
?
海綿寶寶撒

TA貢獻1809條經(jīng)驗 獲得超8個贊

這段代碼是錯誤的,缺少一些引號


$mail->Body = '


    Booking request from '.$forename.' with email '.$email;'

    Test Values: $forename $surname $email $phone $service $date $time

要在字符串上啟用變量替換,請使用雙引號,并且您不需要使用 dot(.) 連接變量,這也可以使用像 \n 這樣的轉義字符,嘗試像這樣調(diào)整您的代碼:


$mail->Body = "Booking request from $forename with email $email\n" .

              "Test Values: $forename $surname $email $phone $service $date $time";


查看完整回答
反對 回復 2022-01-02
?
侃侃無極

TA貢獻2051條經(jīng)驗 獲得超10個贊

首先,我們必須查看錯誤,因此您必須設置

$mail->SMTPDebug = 0;

進入

$mail->SMTPDebug = 3;

因此,您可以根據(jù)該錯誤發(fā)布該錯誤。


查看完整回答
反對 回復 2022-01-02
  • 3 回答
  • 0 關注
  • 231 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號