【问题标题】:phpmailer wont send email after submitting form提交表单后phpmailer不会发送电子邮件
【发布时间】:2017-09-20 22:49:15
【问题描述】:



我在搞乱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 = 'secret@secret.com';          // 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('secret@secret.com', 'Mailer');
$mail->addAddress('secret@secret.com', 'secret');     // Add a recipient
$mail->addAddress('secret@secret.com', 'secret');               // Name is optional
//$mail->addReplyTo('secret@secret.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';


   $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"/>

编辑:错字

编辑:忘了提问题

【问题讨论】:

  • 你使用哪个服务器?
  • @DhruvinMoradiya 我使用自己的服务器(debian 8)
  • 有什么问题??什么不工作?
  • @LelioFaieta 哦,我忘了说。
  • @LelioFaieta 我已经编辑了它,所以它提到了我的问题:)

标签: php html forms email phpmailer


【解决方案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
    )
);

下一个问题是你为什么要这样做?如果你不能提供一个明确的、具体的这样做的理由,那你就做错了。

【讨论】:

    猜你喜欢
    • 2015-03-28
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    • 1970-01-01
    • 1970-01-01
    • 2013-08-15
    相关资源
    最近更新 更多