2017-04-24 92 views
0



我搞亂了phpmailer,我已經得到了一切工作。
但即時嘗試現在要做的是提交表單後發送郵件。 沒有什麼太難,只是一個基本的電子郵件,承認已提交表格(無表格數據)。phpmailer在提交表格後不會發送電子郵件

問題:電子郵件沒有提交表格後發送(電子郵件代碼工作100%測試)

希望有人能幫助我:)

mail.php代碼:

<?php 
//ini_set(‘display_errors’, 1); 

include '/var/www/includes/mailer.php'; 

//require 'PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

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

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp.nicetrygoyim.nl';      //Specify main and backup SMTP servers 
$mail->SMTPAuth = true; // Enable SMTP authentication 


$mail->Username = '[email protected]';   // SMTP username 
$mail->Password = 'nicetry';        // SMTP password 
$mail->SMTPSecure = 'TLS';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;         // TCP port to connect to 

$mail->setFrom('[email protected]', 'Mailer'); 
$mail->addAddress('[email protected]', 'secret');  // Add a recipient 
$mail->addAddress('[email protected]', 'secret');    // Name is optional 
//$mail->addReplyTo('[email protected]', 'Information'); 
//$mail->addCC('[email protected]'); 
//$mail->addBCC('[email protected]'); 

//$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'; 


    $mail->smtpConnect([ 
    'ssl' => [ 
    'verify_peer' => false, 
    'verify_peer_name' => false, 
    'allow_self_signed' => true 
    ] 
     ]); 

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

我的表:

<form action="mail.php" method="post"> 
Leerlingnummer:<br> 
<input type="text" name="leerlingnummer"required placeholder="Voer hier het leerlingnummer in" /><br> 
E-mailadres:<br> 

<input type="submit" name="submit" class="groottext" value="Reparatie indienen"/> 

編輯:錯字

編輯:忘了提問題

+0

您使用哪臺服務器? –

+0

@DhruvinMoradiya我使用我自己的服務器(debian 8) –

+0

,這是什麼問題?什麼不起作用? –

回答

1

如果此代碼運行時,你應該看到一噸的調試輸出,即使它正常工作。你實際上沒有說出什麼問題,但你正在做一些我能看到的錯誤。如果你根據提供的示例編寫代碼並閱讀the docs而不是猜測,這將非常有幫助。

$mail->SMTPSecure = 'TLS'; 

應該是:

$mail->SMTPSecure = 'tls'; 

不要叫smtpConnect()你自己,你會搞砸了SMTP交易狀態的跟蹤。如果你想設置SSL參數,可以將它們預期的方式,然後就打電話send(),將處理的連接:

$mail->SMTPOptions = array(
    'ssl' => array(
     'verify_peer' => false, 
     'verify_peer_name' => false, 
     'allow_self_signed' => true 
    ) 
); 

下一個問題是,爲什麼要那樣做?如果你不能提供明確的具體理由,你做錯了什麼。

+0

我自己修復它,但這有助於很多謝謝:) –