2017-04-24 123 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

我自己修复它,但这有助于很多谢谢:) –